|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|2 초||128 MB||8||7||3||100.000%|
A telephone company wants to build a new telephone network in a city. The company has the goal that each person in the city should be able to call each other person. Of course, it is not possible to build direct connections between every pair of persons. Instead, the company uses a network made up of several layers.
We denote a network switch in layer j by S(j). A switch S(0) consists of one input, one output and a cable connecting the input to the output. A switch S(j) with j > 0 consists of 2j inputs, 2j outputs and two switches S(j - 1). Input i of S(j) (0 ≤ i < 2j) is connected via a cable to the inputs i mod 2j-1 of each of the two switches S(j - 1). Similarly, output i of S(j) is connected to the outputs i mod 2j-1 of each of the two switches S(j - 1).
The connections between a switch S(j) and the two switches S(j - 1) it consists of.
We are considering a network with one switch S(n) in the outermost layer. It can be shown that any input and output of switch S(n) has a unique connection path to any of the S(0) switches. Therefore, any input of S(n) can be connected to any of its outputs, and the connection path is uniquely determined by specifying through which switch S(0) the connection is established.
We number the switches S(0) belonging to the switch S(n) from 0 to 2n - 1. The i-th switch S(0) is defined as follows. Write the number i in binary as bn-1bn-2...b0. This defines a path from an input of S(n) to the i-th switch S(0) via the following procedure: for each j, bj = 0 indicates that the path extends from S(j + 1) to the first S(j) switch to which it is directly connected, and bj = 1 indicates that the path extends to the second S(j) switch. Note that regardless of which input of S(n) is selected, this path arrives at the same S(0) switch, which is given the number i. See also the figure below the sample data for details of how the numbering works.
Sometimes multiple connections are needed at the same time. In order to avoid interference, each of the inputs and outputs of all switches S(j) (0 ≤ j ≤ n) can be used by at most one connection. Given a set of connection requests, can you find connection paths for each request such that the connection paths are disjoint?
On the first line a positive integer: the number of test cases, at most 100. After that per test case:
Per test case:
The connection paths should be disjoint. You may print any valid solution, and you may assume that there is at least one valid solution.
2 1 1 0 1 3 5 0 3 1 4 2 5 3 6 4 7
0 3 0 1 2 4
A possible connection scheme for the second sample case, with used cables in bold.