#P1583B. Omkar and Heavenly Tree
Omkar and Heavenly Tree
Description
Lord Omkar would like to have a tree with nodes () and has asked his disciples to construct the tree. However, Lord Omkar has created () restrictions to ensure that the tree will be as heavenly as possible.
A tree with nodes is an connected undirected graph with nodes and edges. Note that for any two nodes, there is exactly one simple path between them, where a simple path is a path between two nodes that does not contain any node more than once.
Here is an example of a tree:

A restriction consists of pairwise distinct integers, , , and (). It signifies that node cannot lie on the simple path between node and node .
Can you help Lord Omkar and become his most trusted disciple? You will need to find heavenly trees for multiple sets of restrictions. It can be shown that a heavenly tree will always exist for any set of restrictions under the given constraints.
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains two integers, and (, ), representing the size of the tree and the number of restrictions.
The -th of the next lines contains three integers , , (, , , are distinct), signifying that node cannot lie on the simple path between nodes and .
It is guaranteed that the sum of across all test cases will not exceed .
For each test case, output lines representing the edges in the tree. On each line, output two integers and (, ) signifying that there is an edge between nodes and . Given edges have to form a tree that satisfies Omkar's restrictions.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains two integers, and (, ), representing the size of the tree and the number of restrictions.
The -th of the next lines contains three integers , , (, , , are distinct), signifying that node cannot lie on the simple path between nodes and .
It is guaranteed that the sum of across all test cases will not exceed .
Output
For each test case, output lines representing the edges in the tree. On each line, output two integers and (, ) signifying that there is an edge between nodes and . Given edges have to form a tree that satisfies Omkar's restrictions.
Note
The output of the first sample case corresponds to the following tree:

The output of the second sample case corresponds to the following tree:
