Ingenious Lottery Tickets
Time limit2sMemory limit512 MB
Count how often each number 1 to 49 appears across n lottery entries, then pick the six most frequent, breaking ties by favoring 7 and then smaller numbers.
Problem
Your friend Superstitious Stanley is always getting himself into trouble. This time, in his Super Lotto Pick and Choose plan, he wants to get rich quick by choosing the right numbers to win the lottery. In this lottery, an entry consists of six distinct integers from to , written in increasing order. Stanley has compiled a list of the winning entries from the last days and will use it to pick his numbers.
Stanley chooses the six numbers that appeared most often. When he breaks ties, he prefers smaller numbers, except that he prefers to every other number. What is Stanley's entry?
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 winning entries Stanley compiled. Each of the next lines contains one winning entry: six distinct integers from to in increasing order, separated by spaces.
Output
For each test case, print one line containing Stanley's six numbers in increasing order, separated by spaces.
Hint
In the first test case, each of the numbers to appears twice, and every other number appears at most once.
In the second test case, each of the numbers to appears twice. By the tie-breaking rule, Stanley picks first and then the five smallest numbers.