#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define mod2 998244353
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define vi vector<ll>
#define pb push_back
#define ld long double
#define vpi vector<pair<ll,ll>>
#define vvi vector<vector<ll>>

#define debug(a) { cout << #a << " = " << a << endl;}

void sep(string SS = "BLOCK") {
    cout << "-------------" << SS << "-----------------\n";
}

template<typename t>
void pr(t a) {
    cout << a << endl;
}

template<typename t>
void prs(t a) {
    cout << a <<  " ";
}

template<typename T>
void debugv(vector<T> arr) {
    for (auto t: arr)
        cout << t << " ";
    cout << "\n";
}

template<typename T>
void debugarr(T arr, int n) {
    for (int i=0;i<n;i++) cout << arr[i] << " ";
    cout << "\n";
}

template<typename T>
void chmax(T& a, T b) {
    if (a < b)
        a = b;
}

template<typename T>
void chmin(T& a, T b) {
    if (a > b)
        a = b;
}

ll min(ll a, ll b) {
    return a < b ? a : b;
}

ll max(ll a, ll b) {
    return a > b ? a : b;
}

const int maxn = 4e6+100;
const ll INF = 1e18;
ll a[maxn], n, m, t, k, q;
set<ll> s;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin>>t;
    while (t--) {
        cin>>n;
        map<ll,ll> u;
        for (ll i=0;i<n;i++) {
            cin>>a[i]; ++u[a[i]];
        }
        set<ll> s;
        for (pi p: u) s.insert(p.second);
        ll res = INF;
        for (ll x: s) {
            ll tot = 0;
            for (pi p: u) {
                if (p.second < x) tot += p.second;
                else tot += p.second - x;
            }
            chmin(res, tot);
        }
        pr(res);
    }
}

