Bridges

No attempts yetTime limit2sMemory limit128 MB

Problem

In the two-dimensional kingdom of the Flatlanders, every important place sits at a point of the form (X,0)(X, 0), where XX is a positive integer.

The king has ordered NN pairs of important places to be joined by bridges. A bridge between (A,0)(A, 0) and (B,0)(B, 0) (with A<BA < B) is a polyline made of three segments: from (A,0)(A, 0) to (A,P)(A, P), then from (A,P)(A, P) to (B,P)(B, P), then from (B,P)(B, P) to (B,0)(B, 0), where the positive integer PP is called the level of the bridge. The NN bridges must all have different levels, and those levels are exactly the integers from 11 to NN.

Bridges may cross one another, but every crossing is technically inconvenient. Assign a level to each bridge so that the total number of points where two bridges cross is as small as possible. Because all vertical segments have distinct xx-coordinates and all horizontal segments have distinct heights, two bridges can only cross where the vertical part of one meets the horizontal part of the other. Each place appears in the list of pairs at most once.

Input

The first line contains one integer ZZ (Z=1Z = 1), the number of test cases. The test cases follow.

Each test case begins with a line containing one integer NN (1N50001 \le N \le 5000), the number of pairs of places to connect. Each of the next NN lines contains two integers AA and BB (1A<B2N1 \le A < B \le 2N), meaning the places at (A,0)(A, 0) and (B,0)(B, 0) must be joined by a bridge. Since every place is listed at most once, the 2N2N coordinates are exactly the integers from 11 to 2N2N.

Output

For each test case, print one line. List the bridge numbers in increasing order of their assigned levels, separated by single spaces: first the bridge placed at level 11, then the bridge at level 22, and so on up to level NN. Bridges are numbered by their order in the input, starting from 11.

The assignment must minimize the total number of crossings. If several assignments reach that minimum, print the lexicographically smallest sequence: the one whose bridge number at level 11 is as small as possible, then, among those, whose bridge number at level 22 is as small as possible, and so on.

Hint

Write (x1,x2,,xN)(x_1, x_2, \ldots, x_N) for the assignment that puts bridge xix_i at level ii.

In the first test case, both (2,3,1)(2, 3, 1) and (3,2,1)(3, 2, 1) produce 00 crossings, which is clearly the smallest possible. Of the two, (2,3,1)(2, 3, 1) is lexicographically smaller, so it is the answer.