You are given an array $$$a_1, a_2, \dots, a_n$$$, consisting of $$$n$$$ integers.
In one operation, you are allowed to perform one of the following actions:
Note that the elements affected by an operation may already be equal to $$$a_i$$$, but that doesn't change the cost.
You are allowed to perform any number of operations (including zero). What is the minimum total cost to make all elements of the array equal?
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 5 \cdot 10^5$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$).
The sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, print a single integer — the minimum total cost of operations to make all elements of the array equal.
342 4 1 331 1 1107 5 5 5 10 9 9 4 6 10
3 0 35
In the first test case, you can perform the operation twice:
The total cost is $$$2 + 1 = 3$$$.
In the second test case, all elements are already equal, so no operations need to be performed.
| Name |
|---|


