#include <bits/stdc++.h>
using namespace std;
const int N = 2000010;
vector<int> freqs;
int t, n, k, a[N], f[N], vis[N];
int main() {
  cin >> t;
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
      f[i] = 0, vis[i] = 0;
    }
    for (int i = 1; i <= n; ++i) {
      scanf("%d", a + i);
      ++f[a[i]];
    }
    int minFreq = n + n;
    for (int i = 1; i <= n; ++i) {
      if (f[i]) ++vis[f[i]], minFreq = min(minFreq, f[i]);
    }
    freqs.clear();
    for (int i = 1; i <= n; ++i)
      if (vis[i]) {
        freqs.emplace_back(i);
      }
    int ans = n;
    for (int s = 1; s <= minFreq; ++s) {
      int bad = 0, m = 0;
      for (int it : freqs) {
        int x = (it + s) / (s + 1);
        if (x * s > it) {
          bad = 1;
          break;
        }
        m += vis[it] * x;
      }
      if (bad) continue;
      ans = min(ans, m);
    }
    printf("%d\n", ans);
  }
  return 0;
}
