#K70107. Most Repeated Integer
Most Repeated Integer
Most Repeated Integer
You are given several test cases. In each test case, you are given an integer n and a list of n integers. Your task is to determine the integer that appears most frequently in the list. In case of a tie (i.e. when more than one integer has the same maximum frequency), you must output the smallest integer among those.
Formally, if the frequency of an integer x is denoted by \(f(x)\), then you need to find the integer \(x\) such that \(f(x) = \max_{y} f(y)\) and, if multiple \(x\) satisfy this condition, choose \(\min\{x\}\).
inputFormat
The input begins with an integer T on the first line, representing the number of test cases. Each test case consists of two lines:
- The first line contains a single integer n, the number of elements in the array.
- The second line contains n space-separated integers.
outputFormat
For each test case, output a single line containing the integer that is repeated most frequently. In case of a tie, output the smallest integer among them.
## sample1
5
1 2 2 3 1
1
</p>