J. Period of Matrix
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You are given a matrix $$$\textbf{M}$$$ with $$$n$$$ rows and $$$n$$$ columns. Let's define $$$f(i,j,k)=[(\textbf{M}^k)_{i,j}\neq 0]$$$. For each pair of $$$(i,j)$$$ ($$$1\leq i,j\leq n$$$), find the smallest positive integer $$$t$$$ such that $$$f(i,j,k)=f(i,j,k+t)$$$ always holds when $$$k$$$ is sufficiently large.

Note that matrix multiplication should be calculated under $$$\mathbb{Z}$$$.

Input

The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 20$$$), the number of test cases. For each test case:

The first line contains a single integer $$$n$$$ ($$$1\leq n\leq 60$$$).

Each of the next $$$n$$$ lines contains a binary string of length $$$n$$$. The $$$j$$$-th bit of the $$$i$$$-th string denotes $$$\textbf{M}_{i,j}$$$ ($$$1\leq i,j\leq n$$$). In other words, all the values in $$$\textbf{M}$$$ are in $$$\{0,1\}$$$.

Output

For each test case, output $$$n$$$ lines. Output $$$n$$$ integers in the $$$i$$$-th line, the $$$j$$$-th integer of which denoting the smallest positive integer $$$t$$$ such that $$$f(i,j,k)=f(i,j,k+t)$$$ always holds when $$$k$$$ is sufficiently large. Note that if you can not find such $$$t$$$, output "-1" instead.

Example
Input
1
9
010010000
001000001
000100000
010000000
000001000
000000100
000000010
000010001
000000000
Output
1 3 3 3 4 4 4 4 12
1 3 3 3 1 1 1 1 3
1 3 3 3 1 1 1 1 3
1 3 3 3 1 1 1 1 3
1 1 1 1 4 4 4 4 4
1 1 1 1 4 4 4 4 4
1 1 1 1 4 4 4 4 4
1 1 1 1 4 4 4 4 4
1 1 1 1 1 1 1 1 1