CF1623B.Game on Ranges

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Game on Ranges

Alice and Bob play the following game. Alice has a set SS of disjoint ranges of integers, initially containing only one range [1,n][1, n]. In one turn, Alice picks a range [l,r][l, r] from the set SS and asks Bob to pick a number in the range. Bob chooses a number dd (ldrl \le d \le r). Then Alice removes [l,r][l, r] from SS and puts into the set SS the range [l,d1][l, d - 1] (if ld1l \le d - 1) and the range [d+1,r][d + 1, r] (if d+1rd + 1 \le r). The game ends when the set SS is empty. We can show that the number of turns in each game is exactly nn.

After playing the game, Alice remembers all the ranges [l,r][l, r] she picked from the set SS, but Bob does not remember any of the numbers that he picked. But Bob is smart, and he knows he can find out his numbers dd from Alice's ranges, and so he asks you for help with your programming skill.

Given the list of ranges that Alice has picked ([l,r][l, r]), for each range, help Bob find the number dd that Bob has picked.

We can show that there is always a unique way for Bob to choose his number for a list of valid ranges picked by Alice.

Input

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

The first line of each test case contains a single integer nn (1n10001 \le n \le 1000).

Each of the next nn lines contains two integers ll and rr (1lrn1 \le l \le r \le n), denoting the range [l,r][l, r] that Alice picked at some point.

Note that the ranges are given in no particular order.

It is guaranteed that the sum of nn over all test cases does not exceed 10001000, and the ranges for each test case are from a valid game.

Output

For each test case print nn lines. Each line should contain three integers ll, rr, and dd, denoting that for Alice's range [l,r][l, r] Bob picked the number dd.

You can print the lines in any order. We can show that the answer is unique.

It is not required to print a new line after each test case. The new lines in the output of the example are for readability only.

Note

In the first test case, there is only 1 range [1,1][1, 1]. There was only one range [1,1][1, 1] for Alice to pick, and there was only one number 11 for Bob to pick.

In the second test case, n=3n = 3. Initially, the set contains only one range [1,3][1, 3].

  • Alice picked the range [1,3][1, 3]. Bob picked the number 11. Then Alice put the range [2,3][2, 3] back to the set, which after this turn is the only range in the set.
  • Alice picked the range [2,3][2, 3]. Bob picked the number 33. Then Alice put the range [2,2][2, 2] back to the set.
  • Alice picked the range [2,2][2, 2]. Bob picked the number 22. The game ended.

In the fourth test case, the game was played with n=5n = 5. Initially, the set contains only one range [1,5][1, 5]. The game's turn is described in the following table.

Game turn Alice's picked range Bob's picked number The range set after
Before the game start {[1,5]}\{ [1, 5] \}
1 [1,5][1, 5] 33 {[1,2],[4,5]}\{ [1, 2], [4, 5] \}
2 [1,2][1, 2] 11 {[2,2],[4,5]}\{ [2, 2], [4, 5] \}
3 [4,5][4, 5] 55 {[2,2],[4,4]}\{ [2, 2], [4, 4] \}
4 [2,2][2, 2] 22 {[4,4]}\{ [4, 4] \}
5 [4,4][4, 4] 44 {}\{ \} (empty set)

Samples

4
1
1 1
3
1 3
2 3
2 2
6
1 1
3 5
4 4
3 6
4 5
1 6
5
1 5
1 2
4 5
2 2
4 4
1 1 1

1 3 1
2 2 2
2 3 3

1 1 1
3 5 3
4 4 4
3 6 6
4 5 5
1 6 2

1 5 3
1 2 1
4 5 5
2 2 2
4 4 4

在线编程 IDE

建议全屏模式获得最佳体验