#K9636. Most Frequent Value Finder

    ID: 39069 Type: Default 1000ms 256MiB

Most Frequent Value Finder

Most Frequent Value Finder

You are given (T) test cases. For each test case, you have (N) integers. Your task is to determine the most frequently occurring integer and its frequency. In the event of a tie (multiple integers having the same maximum frequency), choose the smallest integer among them.

Mathematically, for a given test case with integers (a_1, a_2, \ldots, a_N), define (f(x)) as the frequency of integer (x) in the test case. You need to find an integer (x) such that (f(x)=\max_{y}(f(y))) and if there are multiple such (x), choose (x=\min{y: f(y)=\max_{y}(f(y))}).

inputFormat

The input is provided via standard input (stdin). The first line contains an integer (T), the number of test cases. Then for each test case, the first line contains an integer (N) (the number of integers in the test case), followed by a second line containing (N) space-separated integers.

outputFormat

For each test case, print a single line on standard output (stdout) containing two space-separated integers: the most frequent integer and its frequency.## sample

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

2 2

</p>