#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<ll>
#define s second
#define f first
using namespace std;
const ll mod=1e9+7;
const ll nmod=998244353;
ll check(double p)
{
	for(int i=0;i<5;i++)
	{
		if((ll)p==pow(2,i))
		{
			return 1;
		}
	}
	return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
    	ll n;
    	cin>>n;
    	ll a[n];
    	map<ll,ll> mp;
    	for(int i=0;i<n;i++)
    	{
    		cin>>a[i];
    		mp[a[i]]++;
		}
		map<ll,ll> :: iterator it;
		vi v;
		for(it=mp.begin();it!=mp.end();it++)
		{
			v.pb(it->s);
		}
		sort(v.begin(),v.end());
		ll ans=n;
		ll sum[v.size()];
		sum[0]=v[0];
		for(int i=1;i<v.size();i++)
		{
			sum[i]=(sum[i-1]+v[i]);
		}
		ll m=v.size();
		for(int i=0;i<v.size();i++)
		{
			ll p=n-(m-i)*v[i];
			ans=min(ans,p);
		}
		cout<<ans<<"\n";
	}
    return 0;
}