Problem: Let's call an array beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):
- choose an index () such that , and replace with .
You are given a beautiful array . What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.
Input Format: The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer ().
The second line contains integers ().
Additional constraints on the input:
- in every test case, the given array is beautiful;
- the sum of over all test cases does not exceed .
Output Format: For each test case, output a single integer — the minimum number of elements you have to remove from the array in order for it to stop being beautiful. If it is impossible, then output -1.
Note: In the first testcase, it is impossible to modify the array in such a way that it stops being beautiful. An array consisting of identical numbers will remain beautiful no matter how many numbers we remove from it.
In the second testcase, you can remove the number at the index , for example.
The resulting array will be . Let's check if it is beautiful. Two operations are available:
- Choose : the array becomes . No more operations can be applied to it, and the numbers are not all the same.
- Choose instead: the array becomes . No more operations can be applied to it either, and the numbers are still not all the same.
Thus, the array is not beautiful.
In the fourth testcase, you can remove the first three elements, for example. The resulting array is not beautiful.