There are $$$n$$$ nests in a forest. These nests are connected by $$$n-1$$$ branches, forming a tree structure. From any nest, a crow can reach any other nest by flying along the branches, and there are no cycles.
A wise old crow wants to travel through all nests exactly once. It can fly in a straight path from one nest to the next if there exists a branch between those nests. The crow already decided the exact order in which it wants to visit the nests.
However, the current branch structure may not form a single straight path. To help the crow, you are allowed to carefully rearrange branches.
Your task is to transform the initial tree structure of nests into the desired chain structure using at most $$$n^2$$$ rearrangement operations.
In one rearrangement operation, you can choose three distinct nests $$$a,b,c$$$ such that the branches $$$(a,b)$$$ and $$$(b,c)$$$ exist in the current tree. Then perform the following change:
The first line contains an integer $$$t$$$ — the number of test cases.
For each test case:
It is guaranteed that the given branches form a tree structure.
The sum of $$$n^2$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case:
Each printed move must be valid at the moment it is applied. After all moves, the remaining branches must create the desired chain structure $$$p_1,p_2,\dots,p_n$$$.
1 4 1 2 3 4 2 1 2 3 2 4
1 4 2 3
Initial branches are $$$(2,1)$$$, $$$(2,3)$$$, $$$(2,4)$$$.
The move $$$[4\; 2\; 3]$$$ removes branch $$$(4,2)$$$ and adds branch $$$(4,3)$$$.
After the move, the branches become $$$(1,2)$$$, $$$(2,3)$$$, $$$(3,4)$$$, which forms the required chain $$$1-2-3-4$$$.