#C3425. Find the Mode

    ID: 46851 Type: Default 1000ms 256MiB

Find the Mode

Find the Mode

You are given T test cases. For each test case, you are provided with a list of numbers. The first number in each test case is N, the count of the following numbers. The remaining N integers are the elements of the list.

Your task is to determine the mode of the list. The mode is defined as the number that appears most frequently in the list. In case there are multiple numbers with the same highest frequency, output the smallest one among them.

Formally, if the list is represented as \(a_1, a_2, \ldots, a_N\), find the number \(x\) such that:

\[ x = \min\{ y \mid \text{frequency}(y) = \max_{z} \text{frequency}(z) \} \]

Read input from stdin and write the result for each test case to stdout, one result per line.

inputFormat

The first line of input contains a single integer T, representing the number of test cases. Each of the next T lines represents a test case and begins with an integer N followed by N integers separated by spaces.

outputFormat

For each test case, output a single line with the mode of the list. If there are multiple modes, output the smallest one.

## sample
2
5 1 2 2 3 3
6 4 5 6 5 6 6
2

6

</p>