#include <bits/stdc++.h>
using namespace std;
int t;
int n;
int f[2000005];
int cnt[2000005], val[2000005];
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i <= n + 3; i++) f[i] = cnt[i] = val[i] = 0;
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      f[x]++;
    }
    int tot = 0;
    for (int i = 1; i <= n; i++) {
      if (f[i] == 0) continue;
      tot++;
      for (int s = 1; s <= f[i] + 1; s++) {
        long long y = (s - f[i] % s) % s;
        long long b = y * (s - 1);
        if (b > 1ll * f[i]) continue;
        long long d = f[i] - b;
        if (d % s) continue;
        long long x = d / s;
        val[s] += x + y;
        cnt[s]++;
      }
    }
    int ans = n;
    for (int i = 1; i <= n; i++)
      if (cnt[i] == tot) ans = min(ans, val[i]);
    cout << ans << '\n';
  }
  return 0;
}
