Join My Team

No attempts yetTime limit1sMemory limit256 MB

Problem

You are running a contest where the organizers assign the teams instead of letting the participants pick their own. Every participant hands in a list of all the other participants, ordered by how much they want that person as a teammate. The first name on the list is the person they want most, the last name is the person they want least.

Assign all NN participants to teams of exactly two. The participants reject an assignment when there are four different participants A, B, C, D such that A is on a team with C, B is on a team with D, A wants B more than C, and B wants A more than D. An assignment with no such four participants is called good.

Several good assignments can exist, so only one of them counts as the answer. Let pip_i be the partner of participant ii. Among all good assignments, report the one whose sequence p1,p2,,pNp_1, p_2, \dots, p_N is lexicographically smallest. One sequence is lexicographically smaller than another when it holds the smaller value at the first position where the two sequences differ.

Input

The first line holds the number of test cases TT.

Each test case starts with a line holding the number of participants NN. Line ii of the following NN lines holds the preference list of participant ii, given as Pi1,Pi2,,Pi(N1)P_{i1}, P_{i2}, \dots, P_{i(N-1)} separated by spaces. The list names every participant other than ii, ordered from the one participant ii wants most to the one participant ii wants least, and each of the other N1N-1 participants appears exactly once.

  • 1T201 \le T \le 20
  • 2N1002 \le N \le 100
  • 1PijN1 \le P_{ij} \le N
  • PijiP_{ij} \ne i

Output

Print one line for each test case.

If a good assignment exists, print the lexicographically smallest one as a list of teams. Write each team as i:j with i<ji < j, sort the teams by increasing ii, and separate them with single spaces.

If no good assignment exists, print NO SOLUTION.