#P1710D. Recover the Tree

    ID: 7829 Type: RemoteJudge 3000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>constructive algorithmstrees*3400

Recover the Tree

No submission language available for this problem.

Description

Rhodoks has a tree with nn vertices, but he doesn't remember its structure. The vertices are indexed from 11 to nn.

A segment [l,r][l,r] (1lrn1 \leq l \leq r \leq n) is good if the vertices with indices ll, l+1l + 1, ..., rr form a connected component in Rhodoks' tree. Otherwise, it is bad.

For example, if the tree is the one in the picture, then only the segment [3,4][3,4] is bad while all the other segments are good.

For each of the n(n+1)2\frac{n(n+1)}{2} segments, Rhodoks remembers whether it is good or bad. Can you help him recover the tree? If there are multiple solutions, print any.

It is guaranteed that the there is at least one tree satisfying Rhodoks' description.

Each test contains multiple test cases. The first line contains the number of test cases tt (1t10001 \leq t \leq 1000). The description of the test cases follows.

The first line of each test case contains an integer nn (1n20001 \leq n \leq 2000) — the number of vertices in the tree.

Then nn lines follow. The ii-th of these lines contains a string goodigood_i of length n+1in+1-i consisting of 0 and 1. If the segment [i,i+j1][i,i+j-1] is good then the jj-th character of goodigood_i is 1, otherwise jj-th character of goodigood_i is 0.

It is guaranteed that the there is at least one tree consistent with the given data.

It is guaranteed that the sum of nn over all test cases does not exceed 20002000.

For each test case, print n1n-1 lines describing the tree you recover.

The ii-th line should contain two integers uiu_i and viv_i (1ui,vin1 \leq u_i,v_i \leq n), denoting an edge between vertices uiu_i and viv_i.

If there are multiple solutions, print any.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t10001 \leq t \leq 1000). The description of the test cases follows.

The first line of each test case contains an integer nn (1n20001 \leq n \leq 2000) — the number of vertices in the tree.

Then nn lines follow. The ii-th of these lines contains a string goodigood_i of length n+1in+1-i consisting of 0 and 1. If the segment [i,i+j1][i,i+j-1] is good then the jj-th character of goodigood_i is 1, otherwise jj-th character of goodigood_i is 0.

It is guaranteed that the there is at least one tree consistent with the given data.

It is guaranteed that the sum of nn over all test cases does not exceed 20002000.

Output

For each test case, print n1n-1 lines describing the tree you recover.

The ii-th line should contain two integers uiu_i and viv_i (1ui,vin1 \leq u_i,v_i \leq n), denoting an edge between vertices uiu_i and viv_i.

If there are multiple solutions, print any.

Samples

Sample Input 1

<div class="test-example-line test-example-line-even test-example-line-0">3</div><div class="test-example-line test-example-line-odd test-example-line-1">4</div><div class="test-example-line test-example-line-odd test-example-line-1">1111</div><div class="test-example-line test-example-line-odd test-example-line-1">111</div><div class="test-example-line test-example-line-odd test-example-line-1">10</div><div class="test-example-line test-example-line-odd test-example-line-1">1</div><div class="test-example-line test-example-line-even test-example-line-2">6</div><div class="test-example-line test-example-line-even test-example-line-2">111111</div><div class="test-example-line test-example-line-even test-example-line-2">11111</div><div class="test-example-line test-example-line-even test-example-line-2">1111</div><div class="test-example-line test-example-line-even test-example-line-2">111</div><div class="test-example-line test-example-line-even test-example-line-2">11</div><div class="test-example-line test-example-line-even test-example-line-2">1</div><div class="test-example-line test-example-line-odd test-example-line-3">12</div><div class="test-example-line test-example-line-odd test-example-line-3">100100000001</div><div class="test-example-line test-example-line-odd test-example-line-3">11100000001</div><div class="test-example-line test-example-line-odd test-example-line-3">1000000000</div><div class="test-example-line test-example-line-odd test-example-line-3">100000000</div><div class="test-example-line test-example-line-odd test-example-line-3">10010001</div><div class="test-example-line test-example-line-odd test-example-line-3">1110000</div><div class="test-example-line test-example-line-odd test-example-line-3">100000</div><div class="test-example-line test-example-line-odd test-example-line-3">10000</div><div class="test-example-line test-example-line-odd test-example-line-3">1001</div><div class="test-example-line test-example-line-odd test-example-line-3">111</div><div class="test-example-line test-example-line-odd test-example-line-3">10</div><div class="test-example-line test-example-line-odd test-example-line-3">1</div><div class="test-example-line test-example-line-odd test-example-line-3"></div>

Sample Output 1

1 2
2 3
2 4
1 2
2 3
3 4
4 5
5 6
2 3
6 7
10 11
2 4
6 8
10 12
1 4
5 8
9 12
5 12
2 12

Note

The first test case is explained in the statement.

In the second test case, one possible tree is as follows:

In the third test case, one possible tree is as follows: