#include <stdio.h> 
#include <iostream> 
#include <vector> 
#include <fstream> 
#include <strstream> 
#include <sstream> 
#include <cassert> 
#include <set> 
#include <map> 
#include <iomanip> 
#include <iterator> 
#include <algorithm> 
#include <list> 
#include <string> 
#include <cmath> 
#include <random>
#include<unordered_map>
#include <fstream>
#include <queue>
using namespace std;


#define mp make_pair 
#define pb push_back 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;


#pragma warning(disable : 4996) 
const ll MOD = 998244353;
const int inf = -1;


void countSort(vector<ll>& arr)
{
    ll max = *max_element(arr.begin(), arr.end());
    ll min = *min_element(arr.begin(), arr.end());
    ll range = max - min + 1;

    vector<ll> count(range), output(arr.size());
    for (int i = 0; i < arr.size(); i++)
        count[arr[i] - min]++;

    for (int i = 1; i < count.size(); i++)
        count[i] += count[i - 1];

    for (int i = arr.size() - 1; i >= 0; i--) {
        output[count[arr[i] - min] - 1] = arr[i];
        count[arr[i] - min]--;
    }

    for (int i = 0; i < arr.size(); i++)
        arr[i] = output[i];
}


int main()
{
#ifdef LIONCHIK
    assert(freopen("in.txt", "r", stdin));
#else
    // assert(freopen(file".in", "r", stdin)); assert(freopen(file".out", "w", stdout));
#endif
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
    int t;
    cin >> t;

    while (t--)
    {
        ll n;
        cin >> n;
        vector<ll> a(n);
        map<ll, ll> m;
        for (auto& x : a)
        {
            cin >> x;
            ++m[x];
        }

        vector<ll> cnts;
        ll sum = 0;
        ll cnts_size = 0;
        for (auto x : m)
        {
            cnts.push_back(x.second);

            sum += x.second;
            ++cnts_size;
        }

        //countSort(cnts);
        sort(cnts.begin(), cnts.end());

        ll c_val = sum - cnts_size *cnts[0];
      
        for (ll i = 1; i < cnts_size; ++i)
        {
       
            if (cnts[i] == cnts[i - 1]) continue;
            ll val = sum - (cnts_size - i) * cnts[i];
            c_val = min(val, c_val);

        } 

        cout << c_val << endl;
        
    }
}
### Prompt

Please formulate 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 <stdio.h> 
#include <iostream> 
#include <vector> 
#include <fstream> 
#include <strstream> 
#include <sstream> 
#include <cassert> 
#include <set> 
#include <map> 
#include <iomanip> 
#include <iterator> 
#include <algorithm> 
#include <list> 
#include <string> 
#include <cmath> 
#include <random>
#include<unordered_map>
#include <fstream>
#include <queue>
using namespace std;


#define mp make_pair 
#define pb push_back 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;


#pragma warning(disable : 4996) 
const ll MOD = 998244353;
const int inf = -1;


void countSort(vector<ll>& arr)
{
    ll max = *max_element(arr.begin(), arr.end());
    ll min = *min_element(arr.begin(), arr.end());
    ll range = max - min + 1;

    vector<ll> count(range), output(arr.size());
    for (int i = 0; i < arr.size(); i++)
        count[arr[i] - min]++;

    for (int i = 1; i < count.size(); i++)
        count[i] += count[i - 1];

    for (int i = arr.size() - 1; i >= 0; i--) {
        output[count[arr[i] - min] - 1] = arr[i];
        count[arr[i] - min]--;
    }

    for (int i = 0; i < arr.size(); i++)
        arr[i] = output[i];
}


int main()
{
#ifdef LIONCHIK
    assert(freopen("in.txt", "r", stdin));
#else
    // assert(freopen(file".in", "r", stdin)); assert(freopen(file".out", "w", stdout));
#endif
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
    int t;
    cin >> t;

    while (t--)
    {
        ll n;
        cin >> n;
        vector<ll> a(n);
        map<ll, ll> m;
        for (auto& x : a)
        {
            cin >> x;
            ++m[x];
        }

        vector<ll> cnts;
        ll sum = 0;
        ll cnts_size = 0;
        for (auto x : m)
        {
            cnts.push_back(x.second);

            sum += x.second;
            ++cnts_size;
        }

        //countSort(cnts);
        sort(cnts.begin(), cnts.end());

        ll c_val = sum - cnts_size *cnts[0];
      
        for (ll i = 1; i < cnts_size; ++i)
        {
       
            if (cnts[i] == cnts[i - 1]) continue;
            ll val = sum - (cnts_size - i) * cnts[i];
            c_val = min(val, c_val);

        } 

        cout << c_val << endl;
        
    }
}
```