You are given a weighted directed graph with n vertices and n(n−1) edges. For any pair of two distinct vertices 1≤i,j≤n, there exists an edge with integer weight w(i,j) where 0≤w(i,j)≤2.
Process the following q queries:
1 a b: Let dist(a,b) be the length of the shortest directed path from vertex a to vertex b (1≤a,b≤n). Output the value min(dist(a,b),2).2 a b c: Update w(a,b) to c (1≤a,b≤n,0≤c≤2,a=b).There are at most 2,000 queries of type 2.
The first line contains two integers n and q (2≤n≤600,1≤q≤106).
The next n lines contain n integers. The j-th integer of the i-th line is w(i,j) (0≤w(i,j)≤2). w(i,i) will be denoted as 0 for all i even though no such edge exists.
The next q lines contain several integers denoting the queries in the described form.
There is at least 1 query of type 1.
There are at most 2,000 queries of type 2.
For each query of type 1, output a single integer denoting the answer to that query. Each answer should go on its own line.