#K45812. Minimum Moves to Equal Elements

    ID: 27837 Type: Default 1000ms 256MiB

Minimum Moves to Equal Elements

Minimum Moves to Equal Elements

You are given an array of integers of size \(n\). In one move, you can choose any two adjacent elements and replace one of them with the other. Your goal is to make all the elements of the array equal using the minimum number of moves.

Consider that if the maximum frequency of any number in the array is \(f_{\max}\), then the minimum number of moves required is given by:

\(\text{moves} = n - f_{\max}\)

You need to process multiple test cases.

inputFormat

The first line contains an integer \(T\), the number of test cases. For each test case, the first line contains an integer \(n\) representing the number of elements in the array. The next line contains \(n\) space-separated integers representing the array.

outputFormat

For each test case, output a single integer representing the minimum number of moves required to make all elements equal. Each answer should be printed on a new line.

## sample
3
4
1 2 2 3
3
5 5 5
5
1 2 3 4 5
2

0 4

</p>