Problem: Polycarpus has a complex electronic device. The core of this device is a circuit board. The board has contact points which are numbered from to . Also there are wires numbered from to , each connecting two distinct contact points on the board. An electric signal can pass between wires and if:
- either both wires share the same contact point;
- or there is a sequence of wires starting with and ending with , and each pair of adjacent wires in the sequence share a contact point.
The picture shows a circuit board with wires. Contact points with numbers are used. Here an electrical signal can pass from wire to wire , but not to wire .
Currently the circuit board is broken. Polycarpus thinks that the board could be fixed if the wires were re-soldered so that a signal could pass between any pair of wires.
It takes minute for Polycarpus to re-solder an end of a wire. I.e. it takes one minute to change one of the two contact points for a wire. Any contact point from range can be used as a new contact point. A wire's ends must always be soldered to distinct contact points. Both wire's ends can be re-solded, but that will require two actions and will take minutes in total.
Find the minimum amount of time Polycarpus needs to re-solder wires so that a signal can pass between any pair of wires. Also output an optimal sequence of wire re-soldering.
Input Format: The input contains one or several test cases. The first input line contains a single integer — number of test cases. Then, test cases follow.
The first line of each test case contains a single integer () — the number of wires. The following lines describe wires, each line containing two space-separated integers (, ) — contact points connected by the -th wire. A couple of contact points can be connected with more than one wire.
Sum of values of across all test cases does not exceed .
Output Format: For each test case first print one line with a single integer — the minimum number of minutes needed to re-solder wires so that a signal can pass between any pair of wires. In the following lines print the description of re-solderings. Each re-soldering should be described by three integers (, ). Such triple means that during the -th re-soldering an end of the -th wire, which was soldered to contact point , becomes soldered to contact point instead. After each re-soldering of a wire it must connect two distinct contact points. If there are multiple optimal re-solderings, print any of them.