#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Max = 2e5 + 1;

int n;

void solve(){
    cin >> n;
    map<ll, ll> idx;
    int x;
    for(int i = 0; i < n; i++){
        cin >> x;
        idx[x]++;
    }
    vector<pair<ll, ll>> a;
    for(auto e : idx){
        a.push_back({e.second, e.first});
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    for(int i = 0; i < a.size(); i++){
        ans = max(ans, ((int)a.size() - i)*a[i].first);
    }
    cout << n - ans << endl;
}

int main (){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
}
