When a competitive programmer thinks of a tree, it's not the same tree that a regular person thinks of. Luckily, in this task, both meanings are correct.
Nikola loves nature and often walks in the woods, looking at the trees and admiring their size, node degrees, paradoxically regular randomness, etc. In this day of lovely spring, there are even more reasons to look above into these magnificent creatures: the trees are full of color and that captured Nikola's attention.
So one day he observed a large tree with
So he needs your help. From the matrix he wrote, determine a possible tree and possible colors of the
respective nodes. Colors should be denoted by numbers from
Input Specification
The first line contains a subtask number (
The second line contains an integer
Each of the next
Output Specification
The first line should contain
Each of the next
Constraints
Subtask | Points | Constraints |
---|---|---|
1 | 18 | All numbers in the matrix equal |
2 | 25 | There is a solution where the tree is a chain of nodes |
3 | 57 | No additional constraints. |
Sample Input 1
3
5
1 2 2 2 3
2 1 3 3 2
2 3 1 3 4
2 3 3 1 3
3 2 4 3 1
Sample Output 1
1 2 3 4 4
1 2
1 3
1 4
2 5
Sample Input 2
2
4
1 2 3 3
2 1 2 2
3 2 1 2
3 2 2 1
Sample Output 2
1 2 3 2
1 2
2 3
3 4
Sample Input 3
1
5
1 2 2 2 2
2 1 1 2 2
2 1 1 2 2
2 2 2 1 2
2 2 2 2 1
Sample Output 3
1 2 2 1 2
1 2
2 3
2 4
1 5
Comments