#P1593D2. Half of Same
Half of Same
Description
This problem is a complicated version of D1, but it has significant differences, so read the whole statement.
Polycarp has an array of ( is even) integers . Polycarp conceived of a positive integer . After that, Polycarp began performing the following operations on the array: take an index () and reduce the number by .
After Polycarp performed some (possibly zero) number of such operations, it turned out that at least half of the numbers in the array became the same. Find the maximum at which such a situation is possible, or print if such a number can be arbitrarily large.
The first line contains one integer () — the number of test cases. Then test cases follow.
Each test case consists of two lines. The first line contains an even integer () ( is even). The second line contains integers ().
It is guaranteed that the sum of all specified in the given test cases does not exceed .
For each test case output on a separate line an integer () — the maximum possible number that Polycarp used in operations on the array, or , if such a number can be arbitrarily large.
Input
The first line contains one integer () — the number of test cases. Then test cases follow.
Each test case consists of two lines. The first line contains an even integer () ( is even). The second line contains integers ().
It is guaranteed that the sum of all specified in the given test cases does not exceed .
Output
For each test case output on a separate line an integer () — the maximum possible number that Polycarp used in operations on the array, or , if such a number can be arbitrarily large.