#include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937 rng(1234);
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  function<void(int, int &, int, int &)> solve_diof = [&](int a, int &x, int b,
                                                          int &y) {
    if (!a) {
      x = 0;
      y = 1;
    } else {
      solve_diof(b % a, x, a, y);
      int xx = y - b / a * x;
      int yy = x;
      x = xx;
      y = yy;
    }
  };
  auto solve = [&](int k, int a, int x, int b, int y) -> pair<bool, int> {
    x *= k;
    y *= k;
    if (x < 0) {
      int t = y / a;
      x += t * b;
      y -= t * a;
      if (x < 0) return {0, -1};
    } else if (y < 0) {
      int t = x / b;
      y += t * a;
      x -= t * b;
      if (y < 0) return {0, -1};
    }
    int t = y / a;
    x += t * b;
    y -= t * a;
    if (x < 0 || y < 0) return {0, -1};
    return {1, x + y};
  };
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> cnt(n);
    for (int i = 0; i < n; ++i) {
      int e;
      cin >> e;
      cnt[e - 1]++;
    }
    sort(cnt.begin(), cnt.end());
    int idx = 0;
    while (!cnt[idx]) ++idx;
    vector<pair<int, int>> sz;
    for (int i = idx; i < n; ++i) {
      if (i == idx || cnt[i] != cnt[i - 1]) {
        sz.emplace_back(cnt[i], 0);
      }
      sz.back().second++;
    }
    int mx = sz.back().first;
    for (auto &s : sz) mx = min(mx, s.first);
    mx++;
    int res = n;
    for (int s = 2; s <= mx; ++s) {
      int x, y;
      int a = s;
      int b = s - 1;
      solve_diof(a, x, b, y);
      int cur = 0;
      bool ok = true;
      for (auto &[k, gs] : sz) {
        auto tmp = solve(k, a, x, b, y);
        if (!tmp.first) {
          ok = false;
          break;
        } else {
          cur += tmp.second * gs;
        }
      }
      if (ok) {
        res = min(res, cur);
      }
    }
    cout << res << "\n";
  }
}
