#P7873. I do not know Graph Theory!

I do not know Graph Theory!

I do not know Graph Theory!

Problem Description

A tournament graph is a directed graph where there is exactly one edge between every two distinct vertices. A strongly connected graph is a directed graph where there is a path between every two distinct vertices. You are given a tournament graph. For each edge of the graph, find out whether the graph is strongly connected when that edge is reversed.

Input

The first line contains one integer TT (1T400001 \leq T \leq 40000), the number of test cases. For each test case, the first line contains one integer nn (2n50002 \leq n \leq 5000), the number of vertices. The next n1n-1 lines give out the compressed lower triangular matrix in the following way: Each line contains an uppercase hexadecimal string, where the jj-th hexadecimal of the ii-th string Si,j=k=032k×Ei+1,4j+k3S_{i,j}=\sum_{k=0}^{3}{2^k \times E_{i+1,4j+k-3}}, and Ei,j=1E_{i,j}=1 iff the direction of the edge between i,ji,j is from ii to jj. All indices start from 11. It is guaranteed that there are at most 33 test cases in which the nn is larger than 1010.

Output

For each test case, output n1n-1 lines in the same format of the input: $S_{i,j}=\sum_{k=0}^{3}{2^k \times ans_{i+1,4j+k-3}}$, and ansi,j=1ans_{i,j}=1 iff the graph is strongly connected when the edge between i,ji,j is reversed.

Sample Input

2
3
0
2
6
1
3
7
F
F1

Sample Output

1
0
0
0
0
0
10

Source

2020 Multi-University Training Contest 10