#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
int n, m, q;
int mark[maxn], po[maxn];
bool am[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 0; i <= n + 3; i++) {
      mark[i] = 0;
      po[i] = 0;
      am[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      mark[x]++;
    }
    vector<int> v, ca;
    for (int i = 1; i <= n; i++)
      if (mark[i]) {
        v.push_back(mark[i]);
        if (am[mark[i]] == 0) {
          am[mark[i]] = 1;
          ca.push_back(mark[i]);
        }
      }
    for (auto k : ca) {
      set<int> cou;
      for (int i = 1; i <= sqrt(k) + 10, i <= k; i++) {
        if (i <= sqrt(k)) cou.insert(i);
        cou.insert(k / i + 1);
        if (k % i == 0) cou.insert(k / i);
      }
      for (auto x : cou) po[x]++;
    }
    int s = 1;
    for (int i = 1; i <= n; i++)
      if (po[i] == ca.size()) s = i;
    int ans = 0;
    for (auto k : v) {
      int hi = k, lo = 1;
      while (hi - lo > 1) {
        int tm = (hi + lo) / 2;
        if ((k + tm - 1) / tm <= s)
          hi = tm;
        else
          lo = tm;
      }
      if (k <= s)
        ans++;
      else
        ans += hi;
    }
    cout << ans << "\n";
  }
}
