#include <map>
#include <ctime>
#include <stack>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
 
inline int read() {
	int x = 0, w = 1;char ch = getchar();
	while (ch > '9' || ch < '0') { if (ch == '-')w = -1;ch = getchar(); }
	while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();
	return x * w;
}
inline void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
 
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9;
 
inline int min(int x, int y) { return x < y ? x : y; }
inline int max(int x, int y) { return x > y ? x : y; }

int t, n, ans, cnt[maxn];

inline int solve() {
    memset(cnt, 0, sizeof(cnt));
    map<int, int> mp; n = read(), ans = 0;
    for (int i = 1, x;i <= n;i++) 
        x = read(), ++mp[x], ++cnt[mp[x]];
    for (int i = 1;i <= n;i++)
        ans = max(ans, i * cnt[i]);
    return n - ans;
}

signed main() { t = read();
    while (t--) printf("%d\n", solve());
    return 0; 
}