#P1710D. Recover the Tree
Recover the Tree
No submission language available for this problem.
Description
Rhodoks has a tree with vertices, but he doesn't remember its structure. The vertices are indexed from to .
A segment () is good if the vertices with indices , , ..., 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 is bad while all the other segments are good.

For each of the 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 (). The description of the test cases follows.
The first line of each test case contains an integer () — the number of vertices in the tree.
Then lines follow. The -th of these lines contains a string of length consisting of 0 and 1. If the segment is good then the -th character of is 1, otherwise -th character of 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 over all test cases does not exceed .
For each test case, print lines describing the tree you recover.
The -th line should contain two integers and (), denoting an edge between vertices and .
If there are multiple solutions, print any.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains an integer () — the number of vertices in the tree.
Then lines follow. The -th of these lines contains a string of length consisting of 0 and 1. If the segment is good then the -th character of is 1, otherwise -th character of 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 over all test cases does not exceed .
Output
For each test case, print lines describing the tree you recover.
The -th line should contain two integers and (), denoting an edge between vertices and .
If there are multiple solutions, print any.
Samples
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:
