#K95117. Most Frequent Element
Most Frequent Element
Most Frequent Element
You are given T test cases. In each test case, you are given a sequence of N integers. Your task is to determine the most frequently occurring element in the sequence. In the case of a tie, you must output the smallest element among those that occur most frequently.
More formally, for a given sequence \(a_1, a_2, \dots, a_N\), let \(f(x)\) denote the frequency of element \(x\). You need to find an element \(x\) such that \(f(x) = \max_{y} f(y)\) and for any other element \(z\) with \(f(z) = f(x)\), \(x \leq z\).
The input is read from standard input (stdin) and the result for each test case must be printed on a new line to standard output (stdout).
inputFormat
The first line contains a single integer T which denotes the number of test cases. For each test case, the first line contains an integer N denoting the number of elements in the sequence. The next line contains N space-separated integers representing the elements of the sequence.
Example:
2 6 1 2 2 3 3 3 4 5 5 4 4
outputFormat
For each test case, output a single integer which is the most frequently occurring element. If there is a tie, output the smallest among them. Each output should be printed on its own line.
Example Output for the example input above:
3 4## sample
2
6
1 2 2 3 3 3
4
5 5 4 4
3
4
</p>