/*Author -> SAMBHU SHOW
Jalpaiguri Govt. Engineering College */
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define itc ll t;cin>>t;while(t--)
#define PI 3.141592653589793238
#define Max(a,b,c) max(a,max(b,c));
#define Min(a,b,c) min(a,min(b,c));
#define all(v) v.begin(),v.end()
#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define gcd(a,b) __gcd(a,b)
#define fi first
#define se second
#define endl "\n"
void solve()
{

    int n;
    cin >> n;

    map<int, int> mp;
    vector<int> ar(n);

    for (int i = 0; i < n; i++)
    {   cin >> ar[i];
        mp[ar[i]]++;
    }

    vector<int> v;

    for (auto x : mp)
        v.push_back(x.se);


    int ans = 0;
    sort(all(v));
    int s = v.size();
    for (int i = 0; i < s; i++)
    {
        ans = max(ans, v[i] * (s - i));
    }
    n -= ans;

    cout << n << endl;
}
int main()
{
    // #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    // #endif
    fio
    itc
    solve();
    return 0;
}