#include <bits/stdc++.h>   using namespace std;   struct edge {     int t, f, w;     bool operator<(const edge& e) const { return w > e.w; }     edge(int from, int to, int weight) {       t = to;       f = from;       w = weight;     }   };   const double EPS = (1e-9);   class UnionFind {    public:     vector<int> p, rank, setSize;     int numSets;     UnionFind(int N) {       setSize.assign(N, 1);       numSets = N;       rank.assign(N, 0);       p.assign(N, 0);       for (int i = 0; i < N; i++) p[i] = i;     }     int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }     bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }     void unionSet(int i, int j) {       if (!isSameSet(i, j)) {         numSets--;         int x = findSet(i), y = findSet(j);         if (rank[x] > rank[y]) {           p[y] = x;           setSize[x] += setSize[y];         } else {           p[x] = y;           setSize[y] += setSize[x];           if (rank[x] == rank[y]) rank[y]++;         }       }     }     int numDisjointSets() { return numSets; }     int sizeOfSet(int i) { return setSize[findSet(i)]; }   };   long long root(long long x) {     long long l = 0, r = 1e9 + 1;     while (l < r - 1) {       long long m = (l + r) / 2;       if (m * m > x)         r = m;       else         l = m;     }     return l;   }   struct line {     double a, b, c;   };   bool areParallel(line l1, line l2) {     return (fabs(l1.a - l2.a) < EPS) && (fabs(l1.b - l2.b) < EPS);   }   bool areSame(line l1, line l2) {     return areParallel(l1, l2) && (fabs(l1.c - l2.c) < EPS);   }   struct point {     double x, y;     point() { x = y = 0.0; }     point(double _x, double _y) : x(_x), y(_y) {}     bool operator<(point other) const {       if (fabs(x - other.x) > EPS) return x < other.x;       return y < other.y;     }   };   void pointsToLine(point p1, point p2, line& l) {     if (fabs(p1.x - p2.x) < EPS) {       l.a = 1.0;       l.b = 0.0;       l.c = -p1.x;     } else {       l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x);       l.b = 1.0;       l.c = -(double)(l.a * p1.x) - p1.y;     }   }   bool areIntersect(line l1, line l2, point& p) {     if (areParallel(l1, l2)) return false;     p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);     if (fabs(l1.b) > EPS)       p.y = -(l1.a * p.x + l1.c);     else       p.y = -(l2.a * p.x + l2.c);     return true;   }   long long binpowmod(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   int findXOR(int n) {     switch (n % 4) {       case 0:         return n;       case 1:         return 1;       case 2:         return n + 1;       case 3:         return 0;     }   }   int rangeXOR(int l, int r) { return (findXOR(l - 1) ^ findXOR(r)); }   int getbit(int mask, int bit) { return (mask & (1 << bit)); }   void setbit(int& mask, int bit, int val) {     if (val)       mask |= (1 << bit);     else       mask &= ~(1 << bit);   }   const int N = 1e5 + 1;   const long long INF = 1e7 + 100;   const int MOD = 1e9 + 7;   class SegmentTree {    private:     vector<pair<int, int>> st;     vector<int> lp;     vector<int> A;     int n;     int left(int p) { return p << 1; }     int right(int p) { return (p << 1) + 1; }     pair<int, int> merge(pair<int, int> p1, pair<int, int> p2) {       if (p1.first == p2.first) return {p1.first, p1.second + p2.second};       if (p1.first < p2.first) return p1;       return p2;     }     void build(int p, int L, int R) {       if (L == R) {         st[p] = {A[L], 1};       } else {         build(left(p), L, (L + R) / 2);         build(right(p), (L + R) / 2 + 1, R);         pair<int, int> p1 = st[left(p)], p2 = st[right(p)];         st[p] = merge(p1, p2);       }     }     pair<int, int> rmq(int p, int L, int R, int i, int j) {       if (i > R || j < L) return {-1, -1};       if (L >= i && R <= j) return st[p];       pair<int, int> p1 = rmq(left(p), L, (L + R) / 2, i, j);       pair<int, int> p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);       if (p1.first == -1) return p2;       if (p2.first == -1) return p1;       return merge(p1, p2);     }     void update_point(int p, int L, int R, int idx, int v) {       int i = idx, j = idx;       if (i > R || j < L) return;       if (L == i && R == j) {         A[L] = v;         st[p] = {v, 1};         return;       }       pair<int, int> p1, p2;       update_point(left(p), L, (L + R) / 2, idx, v);       update_point(right(p), (L + R) / 2 + 1, R, idx, v);       p1 = st[left(p)];       p2 = st[right(p)];       st[p] = merge(p1, p2);     }       public:     SegmentTree(const vector<int>& _A) {       A = _A;       n = (int)A.size();       st.assign(4 * n, {0, 0});       lp.assign(4 * n, 0);       build(1, 0, n - 1);     }     pair<int, int> rmq(int i, int j) { return rmq(1, 0, n - 1, i, j); }     void update_point(int idx, int new_value) {       update_point(1, 0, n - 1, idx, new_value);     }   };   vector<int> freq;   int n;   bool can(int x) {     set<pair<int, int>, greater<pair<int, int>>> s;     vector<int> cnt(n + 1);     for (int i = 1; i <= n; ++i) {       if (freq[i]) {         cnt[i] = freq[i];         s.insert({cnt[i], i});       }     }     vector<int> b;     for (int i = 0; i < n; ++i) {       if (i >= x && cnt[b[i - x]] > 0) {         s.insert({cnt[b[i - x]], b[i - x]});       }       if (s.empty()) return false;       b.push_back(s.begin()->second);       s.erase(s.begin());       cnt[b.back()]--;     }     return true;   }   void solve() {     cin >> n;     freq.assign(n + 1, 0);     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       freq[x]++;     }     int lo = 0, hi = n;     while (hi - lo > 1) {       int mid = (hi + lo) / 2;       if (can(mid)) {         lo = mid;       } else         hi = mid;     }     cout << lo - 1 <<   n ;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc = 1;     cin >> tc;     while (tc--) {       solve();     }   }