#P1521D. Nastia Plays with a Tree
Nastia Plays with a Tree
Description
Nastia has an unweighted tree with vertices and wants to play with it!
The girl will perform the following operation with her tree, as long as she needs:
- Remove any existing edge.
- Add an edge between any pair of vertices.
What is the minimum number of operations Nastia needs to get a bamboo from a tree? A bamboo is a tree in which no node has a degree greater than .
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the number of vertices in the tree.
Next lines of each test cases describe the edges of the tree in form , (, ).
It's guaranteed the given graph is a tree and the sum of in one test doesn't exceed .
For each test case in the first line print a single integer — the minimum number of operations required to obtain a bamboo from the initial tree.
In the next lines print integers , , , (, , ) — this way you remove the edge and add an undirected edge .
Note that the edge must be present in the graph at the moment of removing.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the number of vertices in the tree.
Next lines of each test cases describe the edges of the tree in form , (, ).
It's guaranteed the given graph is a tree and the sum of in one test doesn't exceed .
Output
For each test case in the first line print a single integer — the minimum number of operations required to obtain a bamboo from the initial tree.
In the next lines print integers , , , (, , ) — this way you remove the edge and add an undirected edge .
Note that the edge must be present in the graph at the moment of removing.
Note
Note the graph can be unconnected after a certain operation.
Consider the first test case of the example:
