#include <bits/stdc++.h>
const int N = (int)2e6 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
int n;
int a[N], cnt[N], total[N];
vector<pair<int, int>> cmp;
pair<int, int> get(int cnt, int second) {
  pair<int, int> res = {inf, inf};
  int mn = inf;
  for (int i = (0); i <= (cnt / second); i++) {
    if ((cnt - second * i) % (second - 1) == 0) {
      int big = i, small = (cnt - second * i) / (second - 1);
      if (big + small < mn) {
        mn = big + small;
        res = {big, small};
      }
    }
  }
  return res;
}
pair<int, int> naive(int cnt, int second) {
  int k = cnt / (second - 1), rem = cnt % (second - 1);
  int big = rem, small = k - rem;
  if (small < 0) return {inf, inf};
  big += small / second * (second - 1);
  small %= second;
  return {big, small};
}
int calc(int second) {
  int m = 0;
  for (auto it : cmp) {
    int cnt = it.first / (second - 1), rem = it.first % (second - 1);
    int big = rem, small = cnt - rem;
    if (small < 0) return inf;
    big += small / second * (second - 1);
    small %= second;
    m += (big + small) * it.second;
  }
  return m;
}
void solve() {
  cin >> n;
  for (int i = (1); i <= (n); i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int mn = inf;
  for (int i = (1); i <= (n); i++) {
    if (cnt[i]) {
      total[cnt[i]]++;
      mn = min(mn, cnt[i]);
    }
  }
  for (int i = (1); i <= (n); i++) {
    if (total[i]) {
      cmp.push_back({i, total[i]});
    }
  }
  int m = n;
  for (int second = (2); second <= (mn + 1); second++) {
    m = min(m, calc(second));
  }
  cout << m << '\n';
  for (int i = (1); i <= (n); i++) {
    total[cnt[i]] = 0;
  }
  for (int i = (1); i <= (n); i++) {
    cnt[a[i]] = 0;
  }
  cmp.clear();
}
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  exit(0);
}
