eolymp
bolt
Try our new interface for solving problems

Trade

Trading is a subtle thing. A successful huckster not only should reasonably choose the time to sell the goods and master the art of touting, but also thoroughly examine the market. It's important to know which of the merchants trade with each other and which don't. Sometimes the merchants don't directly trade, but their goods still nd a way to each other via other merchants. For example, if merchants \textbf{A} and \textbf{B} trade directly and merchants \textbf{B} and \textbf{C} trade directly, then goods from \textbf{A} and \textbf{C} will get to each other via merchant \textbf{B}. In general, the goods may get from a merchant to another via any number of intermediate merchants. Another important concept are the inseparable pairs - these are the pairs of merchants which trade directly, and no sequence of intermediate merchants exists through which the merchants in the pair could trade indirectly. Manao wants to become a successful huckster. We don't know what necessary skills he does possess, but he surely lacks the knowledge about market situation. What he currently knows is that there are \textbf{N} merchants at the market, \textbf{M} pairs trade directly and \textbf{K} of them are inseparable. What he needs is the information of sort "\textbf{A} trades with \textbf{B}, \textbf{C} trades with \textbf{D}, \textbf{X} trades with \textbf{A}". In most cases, this is ambiguous, but at the moment any tting scheme would suce. You're given \textbf{T} scenarios with the values of \textbf{N}, \textbf{M} and \textbf{K}. For each of them determine whether a corresponding trade market exists and if yes, output its description. Merchants are numbered in some order from \textbf{1} to \textbf{N}, the description of the trade market is the set of all pairs of merchants who trade directly. \InputFile The first line contains the number of scenarios \textbf{T}. Each of the following \textbf{T} lines contains three numbers \textbf{N}, \textbf{M}, \textbf{K} (\textbf{2} ≤ \textbf{N} ≤ \textbf{100}, \textbf{0} ≤ \textbf{K} ≤ \textbf{M} ≤ \textbf{N}·(\textbf{N} - \textbf{1})/\textbf{2}). The number of scenarios in a single input does \textbf{100}. Sum of \textbf{M}'s over all scenarios in a single input does not exceed \textbf{50000}. \OutputFile For each of the \textbf{T} scenarios output "\textbf{NO SOLUTION}" (without quotes) if the corresponding trade market does not exist. Otherwise, output "\textbf{TRADE MARKET FOUND}", followed by \textbf{M} lines. Each of the lines must contain a pair of numbers separated by a space - the numbers of the merchants trading directly.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
4 3 0
4 2 0
5 5 2
Output example #1
TRADE MARKET FOUND
1 2
2 3
3 1
NO SOLUTION
TRADE MARKET FOUND
1 2
2 3
3 1
1 4
1 5
Author Eldar Bogdanov
Source Winter School, Kharkov, 2011, Day 7