#K71317. Most Frequent Element

    ID: 33505 Type: Default 1000ms 256MiB

Most Frequent Element

Most Frequent Element

You are given multiple test cases. In each test case, you are provided with a list of non-negative integers. Your task is to identify the element that occurs most frequently in the list. If there are multiple elements that have the same highest frequency, choose the smallest element among them.

Formally, given a list A = [a₁, a₂, \dots, aₙ], let the frequency of an integer x be ( f(x) ). You need to find the integer ( x ) such that ( f(x) = \max_{y \in A} f(y) ), and if there are multiple such x, output ( \min{ x : f(x) = \max_{y \in A} f(y) } ).

inputFormat

The first line contains a single integer t, representing the number of test cases. Each of the next t lines describes a test case. Each test case starts with an integer n, indicating the number of elements, followed by n non-negative integers separated by spaces.

Example:

3 6 1 2 2 3 3 3 5 2 2 3 3 4 4 1 1 2 2

outputFormat

For each test case, output one line containing a single integer, which is the most frequent element (choosing the smallest in case of ties).

Example:

3 2 1## sample

3
6 1 2 2 3 3 3
5 2 2 3 3 4
4 1 1 2 2
3

2 1

</p>