#include<bits/stdc++.h>
using namespace std;
long long q,n,c[400005],z,ans,mn=1e14,d,x;
map<long long,long long>las,ll;
vector<long long>v;
struct am{
long long va,ind;
};
am a[400005];
bool cmp(am zz,am y){
return zz.ind<y.ind;
}
set<long long>st;
int main(){
ios::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
cin>>q;

while (q--){
cin>>n;
st.clear();
v.clear();
las.clear();
ll.clear();
mn=1e14;
for (long long i=1;i<=n;i++){
    cin>>x;
    las[x]++;
}
z=1;
for (auto it=las.begin();it!=las.end();it++){
a[z].va=it->first;
a[z].ind=it->second;
z++;
}

sort (a+1,a+z,cmp);
for (long long i=z-1;i>=1;i--){
        x=st.size();
    mn=min(mn,n-(a[i].ind + a[i].ind*x));
st.insert(a[i].va);
}


cout<<mn<<"\n";
}


}
