#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define loop(n) for(int i=1;i<=n;i++)


int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);

	uint t;
	cin>>t;
	while(t--)
	{
		int n,temp,tem;
		ll min=INT_MAX;
		cin>>n;
		map<int,int> a;
		vector<int> s;
		set<int> st;
		loop(n)
		{
			cin>>temp;
			tem=a[temp];
			a[temp]=tem+1;
		}
		for(auto i:a)
		{
			//cout<<i.second<<" ";
			s.push_back(i.second);
			st.insert(i.second);
		}
		for(auto mid:st)		
		{
			ll sum=0;
			for(auto i:s)
				if(i<mid)
					sum+=i;
				else
					sum+=i-mid;
			if(min>sum)
				min=sum;
		}
		cout<<min<<endl;
	}
	return 0;
}