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

//macros
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl
#define f(i,n) for(l i=0;i<n;i++)
#define fo(i,k,n) for(l i=k;i<n;i++)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define vi vector<int> 
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> > 
#define setbits(x) __builtin_popcount(x)
//#define endl '\n'

//vector<int> v[n] --> creates an array (of vectors) of size n where each vector is of size 0 initially.
//vector<int> v(n,k) --> creates a normal vector of size n with initialisation = k.
//vector<vector<int> > v(n) --> creates a vector (of vectors) of size n with each vector of size 0 initially.
//for running multi-source dijkstra --> maintain a vector<vector<pair<int,int> > d; 


typedef long long l; 
const double pi = 3.1415926;
const l M=1e9+7;
const int N=2e5+5;

//vector<int> v;
//vi vis;
//l fac[N];


l power(l x, l y, l p) 
{ 
    l res = 1;  
    x = x % p; 

    while (y > 0) 
    { 
        if (y & 1) 
            res = (res * x) % p; 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
     } 
    return res;
} 

l mi(l x)
{	
    return power(x,M-2,M);
}

int nCr(int n, int r)
{
        int mod = 1000000007;
        int C[r+1];
        memset(C, 0, sizeof(C));
        
        C[0] = 1; // Top row of Pascal Triangle 

    	
    	for (int i = 1; i <= n; i++) { 
    		
    		for (int j = min(i, r); j > 0; j--)
		{ 
                	// nCj = (n-1)Cj + (n-1)C(j-1); 
    			C[j] = (C[j] + C[j-1])%mod;
    		}
    	} 
    	return C[r]%mod;
}
//l ncr(l x,l y)
//{
//	l ans=(((fac[x]*mi(fac[y]))%M)*mi(fac[x-y]))%M;
//	return ans;
//}

//void dfs(int r)
//{
//	for(auto x:v[r])
//	{
//		dfs(x);
//	}
//
//}

int main()
{
	fast_io;
	//memset(vis,0,sizeof(vis));
	//fac[0]=1;
	//fo(i,1,100001)
	//{
	//	fac[i]=(fac[i-1]*i)%M;
	//}

	l t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    l a[n];
	    map<l,int> m;
	    set<l> s;
	    
	    f(i,n)
	    {
	        cin>>a[i];
	        m[a[i]]++;
	    }
	    
	    vector<int> v;
	    for(auto x:m)
	    {
	        v.pb(x.second);
	    }
	    sort(v.begin(),v.end());
	   // l sums[v.size()];
	   // memset(sums,0,sizeof(sums));
	   // sums[0]=v[0];
	   // f(i,v.size())
	   // {
	   //     sums[i]=sums[i-1]+v[i];
	   // }
	    l mn=n-v.size()*v[0];
	    fo(i,1,v.size())
	    {
	        l ans=n-v[i]*(v.size()-i);
	        mn=min(mn,ans);
	    }
	    cout<<mn<<endl;
	    
	  
	    

	}
	
return 0;
}
