#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 100007

ll gcd(ll a, ll b){
	return b?gcd(b, a%b):a;
}

ll lcm(ll a, ll b){
	return a/gcd(a,b)*b;
}

ll a[1000000];


void giai(){
	ll n;
	cin >> n;
	ll b[n];
	for(ll i=0; i<n; i++) cin >> a[i];
	for(ll i=0; i<n; i++) b[i] = a[i];
	sort(a,a+n);	
	vector<ll> val;
	vector<ll> num;
	ll cnt = 1;
	val.push_back(a[0]);
	for(ll i=0; i<n-1; i++) if(a[i] != a[i+1]){
		val.push_back(a[i+1]);
		num.push_back(cnt);
		cnt = 1;
	}else cnt++;
	num.push_back(cnt);
	

	ll si = val.size();
	cnt = 1;
	sort(num.begin(), num.end());

	vector<ll> val2;
	vector<ll> num2;
	val2.push_back(num[0]);
	for(ll i=0; i<si-1; i++) if(num[i] != num[i+1]){
		val2.push_back(num[i+1]);
		num2.push_back(cnt);
		cnt = 1;
	}else cnt++;
	num2.push_back(cnt);

//	ll sum[val2.size()], isum[val2.size()];
//	sum[0] = num2[0];
//	for(ll i=1; i<val2.size(); i++) sum[i] = sum[i-1] + num2[i];
//	isum[val2.size()-1] = num2[val2.size()-1];
//	for(ll i=val2.size()-2; i>=0; i--) isum[i] = isum[i+1] + num2[i];
	ll mn = n;
	for(ll i=0; i<val2.size(); i++){
		ll ans = 0;
		for(ll j=0; j<i; j++) ans += val2[j]*num2[j];
		for(ll j=i+1; j<val2.size(); j++) ans += (val2[j]-val2[i])*num2[j];
		if(ans < mn) mn = ans;
	}
	cout << mn << endl;
}
 

int main(){
   ll g;
   cin >> g;
   while(g--){
   	giai();
   }
//	giai();

}

### Prompt

Generate a cpp solution to the following problem:

Polycarp was gifted an array a of length n. Polycarp considers an array beautiful if there exists a number C, such that each number in the array occurs either zero or C times. Polycarp wants to remove some elements from the array a to make it beautiful.

For example, if n=6 and a = [1, 3, 2, 1, 4, 2], then the following options are possible to make the array a array beautiful: 

  * Polycarp removes elements at positions 2 and 5, array a becomes equal to [1, 2, 1, 2]; 
  * Polycarp removes elements at positions 1 and 6, array a becomes equal to [3, 2, 1, 4]; 
  * Polycarp removes elements at positions 1, 2 and 6, array a becomes equal to [2, 1, 4]; 



Help Polycarp determine the minimum number of elements to remove from the array a to make it beautiful.

Input

The first line contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow.

The first line of each test case consists of one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array a.

The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — array a.

It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.

Output

For each test case, output one integer — the minimum number of elements that Polycarp has to remove from the array a to make it beautiful.

Example

Input


3
6
1 3 2 1 4 2
4
100 100 4 100
8
1 2 3 3 3 2 6 6


Output


2
1
2

### Response

```cpp
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 100007

ll gcd(ll a, ll b){
	return b?gcd(b, a%b):a;
}

ll lcm(ll a, ll b){
	return a/gcd(a,b)*b;
}

ll a[1000000];


void giai(){
	ll n;
	cin >> n;
	ll b[n];
	for(ll i=0; i<n; i++) cin >> a[i];
	for(ll i=0; i<n; i++) b[i] = a[i];
	sort(a,a+n);	
	vector<ll> val;
	vector<ll> num;
	ll cnt = 1;
	val.push_back(a[0]);
	for(ll i=0; i<n-1; i++) if(a[i] != a[i+1]){
		val.push_back(a[i+1]);
		num.push_back(cnt);
		cnt = 1;
	}else cnt++;
	num.push_back(cnt);
	

	ll si = val.size();
	cnt = 1;
	sort(num.begin(), num.end());

	vector<ll> val2;
	vector<ll> num2;
	val2.push_back(num[0]);
	for(ll i=0; i<si-1; i++) if(num[i] != num[i+1]){
		val2.push_back(num[i+1]);
		num2.push_back(cnt);
		cnt = 1;
	}else cnt++;
	num2.push_back(cnt);

//	ll sum[val2.size()], isum[val2.size()];
//	sum[0] = num2[0];
//	for(ll i=1; i<val2.size(); i++) sum[i] = sum[i-1] + num2[i];
//	isum[val2.size()-1] = num2[val2.size()-1];
//	for(ll i=val2.size()-2; i>=0; i--) isum[i] = isum[i+1] + num2[i];
	ll mn = n;
	for(ll i=0; i<val2.size(); i++){
		ll ans = 0;
		for(ll j=0; j<i; j++) ans += val2[j]*num2[j];
		for(ll j=i+1; j<val2.size(); j++) ans += (val2[j]-val2[i])*num2[j];
		if(ans < mn) mn = ans;
	}
	cout << mn << endl;
}
 

int main(){
   ll g;
   cin >> g;
   while(g--){
   	giai();
   }
//	giai();

}

```