/*
 * @Author: hesorchen
 * @Date: 2020-11-26 09:12:46
 * @LastEditTime: 2021-02-17 14:39:18
 * @Description: 栽种绝处的花
 */
#include <bits/stdc++.h>
using namespace std;
long long a[200010];
int n;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        map<long long, long long> mp;
        set<int> st;
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
            ++mp[a[i]];
        }

        long long ans = 1000000000000000;
        for (pair<long long, long long> it : mp)
        {
            st.insert(it.second);
        }
        for (long long it : st)
        {
            long long res = 0;
            for (pair<long long, long long> it2 : mp)
            {
                if (it2.second < it)
                    res += it2.second;
                else if (it2.second >= it)
                    res += it2.second - it;
            }
            ans = min(ans, res);
        }
        cout << ans << '\n';
    }

    return 0;
}

/*


*/
