#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {

	int test;
	cin >> test;
	while (test--) {
		int n;
		cin >> n;
		map <int, int> m;
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			m[a]++;
		}
		int x = 0, counter = 1;
		for (auto a : m) {
			if (a.second > x) {
				x = a.second;
				counter = 1;
			}
			else if (a.second == x) counter++;
		}
		int ost = 0;
		for (auto a : m) {
			if (a.second < x) ost++;
		}

		if (counter > 1) cout << counter - 1 + (ost / 2 +(ost % 2 > 0));
		else cout << (n - x) / (x - 1);
		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {

	int test;
	cin >> test;
	while (test--) {
		int n;
		cin >> n;
		map <int, int> m;
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			m[a]++;
		}
		int x = 0, counter = 1;
		for (auto a : m) {
			if (a.second > x) {
				x = a.second;
				counter = 1;
			}
			else if (a.second == x) counter++;
		}
		int ost = 0;
		for (auto a : m) {
			if (a.second < x) ost += a.second;
		}

		if (counter > 1) cout << counter - 1 + (ost / (x - 1));
		else cout << (n - x) / (x - 1);
		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {

	int test;
	cin >> test;
	while (test--) {
		int n;
		cin >> n;
		map <int, int> m;
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			m[a]++;
		}
		int x = 0, counter = 1;
		for (auto a : m) {
			if (a.second > x) {
				x = a.second;
				counter = 1;
			}
			else if (a.second == x) counter++;
		}
		int ost = 0;
		for (auto a : m) {
			if (a.second < x) ost += a.second;
		}

		if (counter > 1) cout << counter - 1 + (ost / 2 +(ost % 2 > 0));
		else cout << (n - x) / (x - 1);
		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

int arr[10003];

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	int tc, inp;
	cin >> tc;
	for (int t = 0; t < tc; t++) {
		memset(arr, 0, sizeof(arr));
		int n, jugee = 1, nam;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> inp;
			arr[inp]++;
		}
		sort(arr, arr + n + 1, cmp);
		int max_num = arr[0];
		for (int i = 1; i <= n; i++) {
			if (arr[i] == max_num) jugee++;
			else break;
		}
		nam = n - (max_num * jugee);
		if (max_num == 1)cout << n - 2 << endl;
		else cout << jugee - 1 + (nam / (max_num - 1)) << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

int arr[100003];

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	int tc, inp;
	cin >> tc;
	for (int t = 0; t < tc; t++) {
		memset(arr, 0, sizeof(arr));
		map <int, int> m;
		int n, jugee = 1, nam, max_num = 0;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> inp;
			arr[inp]++;
			if (m[arr[inp]] == NULL)
				m[arr[inp]] = 1;
			else
				m[arr[inp]]++;
			if (max_num < arr[inp])max_num = arr[inp];
		}
		jugee = m[max_num];
		nam = n - (max_num * jugee);
		if (max_num == 1)cout << n - 2 << endl;
		else cout << jugee - 1 + (nam / (max_num - 1)) << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

int arr[10001];

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	int tc, inp;
	cin >> tc;
	for (int t = 0; t < tc; t++) {
		memset(arr, 0, sizeof(arr));
		int n, jugee = 1, nam;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> inp;
			arr[inp]++;
		}
		sort(arr, arr + n + 1, cmp);
		int max_num = arr[0];
		for (int i = 1; i < n; i++) {
			if (arr[i] == max_num) jugee++;
			else break;
		}
		nam = n - (max_num * jugee);
		if (max_num == 1)cout << n - 2 << endl;
		else cout << jugee - 1 + (nam / (max_num - 1)) << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

int arr[10003];

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	int tc, inp;
	cin >> tc;
	for (int t = 0; t < tc; t++) {
		memset(arr, 0, sizeof(arr));
		int n, jugee = 1, nam;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> inp;
			arr[inp]++;
		}
		sort(arr, arr + n + 1, cmp);
		int max_num = arr[0];
		for (int i = 1; i < n; i++) {
			if (arr[i] == max_num) jugee++;
			else break;
		}
		nam = n - (max_num * jugee);
		if (max_num == 1)cout << n - 2 << endl;
		else cout << jugee - 1 + (nam / (max_num - 1)) << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

int arr[10003];

bool cmp(int a, int b) {
	return a > b;
}

int main() {
	int tc, inp;
	cin >> tc;
	for (int t = 0; t < tc; t++) {
		memset(arr, 0, sizeof(arr));
		map <int, int> m;
		int n, jugee = 1, nam, max_num = 0;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> inp;
			arr[inp]++;
			if (m[arr[inp]] == NULL)
				m[arr[inp]] = 1;
			else
				m[arr[inp]]++;
			if (max_num < arr[inp])max_num = arr[inp];
		}
		jugee = m[max_num];
		nam = n - (max_num * jugee);
		if (max_num == 1)cout << n - 2 << endl;
		else cout << jugee - 1 + (nam / (max_num - 1)) << endl;
	}
}


#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <functional>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <complex>
#define all(v) (v).begin(),(v).end()
#define sz(v) ((v).size())
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using pdd = pair<double, double>;
using pil = pair<int, ll>;

int n;
int arr[100001];
int cnt[100001];

int main() {
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int tc;
	cin >> tc;
	while (tc--) {
		cin >> n;
		for (int i = 1; i <= n; i++) {
			int x;
			cin >> x;
			cnt[x]++;
		}
		int ans = n + 1;
		int tmp = 0;
		int idx = 0;
		for (int i = 1; i <= n; i++)
			if (cnt[i] != 0)
				arr[cnt[i]]++;
		for(int i=2;i<=n;i++)
			if (arr[i] != 0) {
				if (i == 2 && arr[i] == 1)
					ans = min(ans, n - 2);
				else if (i == 2)
					ans = min(ans, n / i - 1 + (n - arr[i] * i) / (i - 1));
				else if (i == n)
					ans = 0;
				else
					ans = min(ans, (n - i) / (i - 1));
			}
		cout << ans << "\n";
		fill(cnt, cnt + 1 + n, 0);
		fill(arr, arr + 1 + n, 0);
	}

}


#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <functional>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <deque>
#include <complex>
#define all(v) (v).begin(),(v).end()
#define sz(v) ((v).size())
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using pdd = pair<double, double>;
using pil = pair<int, ll>;

int n;
int arr[100001];
int cnt[100001];

int main() {
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int tc;
	cin >> tc;
	while (tc--) {
		cin >> n;
		for (int i = 1; i <= n; i++) {
			int x;
			cin >> x;
			cnt[x]++;
		}
		int ans = n + 1;
		int tmp = 0;
		int idx = 0;
		for (int i = 1; i <= n; i++)
			if (cnt[i] != 0)
				arr[cnt[i]]++;
		for(int i=2;i<=n;i++)
			if (arr[i] != 0) {
				/*if (i == 2) {
					ans = min(ans, (n - i * arr[i]) / (i - 1));
				}
				else if (i == n)
					ans = 0;
				else
					ans = min(ans, (n - i) / (i - 1));*/
				ans = min(ans, arr[i]-1+(n - i * arr[i]) / (i - 1));
			}
		cout << ans << "\n";
		fill(cnt, cnt + 1 + n, 0);
		fill(arr, arr + 1 + n, 0);
	}

}


#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <memory.h>
using namespace std;
const int ARR_SIZE = 100001;

int T;
int n, tmp;
int arr[ARR_SIZE];
int cnt_max, cnt_max_cnt;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> T;
	while (T--)
	{
		cin >> n;
		for (int i = 0; i < ARR_SIZE; i++)
		{
			arr[i] = 0;
		}
		cnt_max = 0;
		cnt_max_cnt = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> tmp;
			arr[tmp]++;
			if (arr[tmp] > cnt_max)
			{
				cnt_max = arr[tmp];
				cnt_max_cnt = 1;
			}
			else if (arr[tmp] == cnt_max)
				cnt_max_cnt++;
		}
		cout << (n - cnt_max_cnt * cnt_max) / (cnt_max - 1) + cnt_max_cnt - 1 << '\n';
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool desc(int a, int b) {
	return a > b;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	int N;
	int temp;
	//int max_cnt;
	//int left, right, mid;
	//int ans;
	int sameCnt;
	int i;

	cin >> T;
	while (T--) {
		cin >> N;
		vector<int> cnt(N + 1, 0);
		for (i = 0; i < N; i++) {
			cin >> temp;
			cnt[temp]++;
		}
		sort(cnt.begin(), cnt.end(), desc);

		if (cnt[0] != cnt[1]) {
			cout << (N - cnt[0]) / (cnt[0] - 1) << '\n';
		}
		else {
			//�ִ� cnt�� ���� ���Ұ� sameCnt���̴�.
			for (sameCnt = 0; cnt[sameCnt] == cnt[0]; sameCnt++);
			cout << sameCnt << '\n';
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool desc(int a, int b) {
	return a > b;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	int N;
	int temp;
	int sameCnt;
	int i;

	cin >> T;
	while (T--) {
		cin >> N;
		vector<int> cnt(N + 1, 0);
		for (i = 0; i < N; i++) {
			cin >> temp;
			cnt[temp]++;
		}
		sort(cnt.begin(), cnt.end(), desc);

		if (cnt[0] != cnt[1]) {
			cout << (N - cnt[0]) / (cnt[0] - 1) << '\n';
		}
		else {
			//for (sameCnt = 0; cnt[sameCnt] == cnt[0]; sameCnt++);
			//cout << sameCnt << '\n';
			cout << N / cnt[0] << '\n';
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool desc(int a, int b) {
	return a > b;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	int N;
	int temp;
	int sameCnt;
	int i;

	cin >> T;
	while (T--) {
		cin >> N;
		vector<int> cnt(N + 1, 0);
		for (i = 0; i < N; i++) {
			cin >> temp;
			cnt[temp]++;
		}
		sort(cnt.begin(), cnt.end(), desc);

		if (cnt[0] != cnt[1]) {
			cout << (N - cnt[0]) / (cnt[0] - 1) << '\n';
		}
		else {
			for (sameCnt = 0; cnt[sameCnt] == cnt[0]; sameCnt++);
			cout << (N - cnt[0] * sameCnt) / (sameCnt - 1) + sameCnt << '\n';
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool desc(int a, int b) {
	return a > b;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	int N;
	int temp;
	int sameCnt;
	int i;

	cin >> T;
	while (T--) {
		cin >> N;
		vector<int> cnt(N + 1, 0);
		for (i = 0; i < N; i++) {
			cin >> temp;
			cnt[temp]++;
		}
		sort(cnt.begin(), cnt.end(), desc);

		if (cnt[0] != cnt[1]) {
			cout << (N - cnt[0]) / (cnt[0] - 1) << '\n';
		}
		else {
			for (sameCnt = 0; cnt[sameCnt] == cnt[0]; sameCnt++);
			cout << (N - cnt[0] * sameCnt) / (cnt[0] - 1) + sameCnt - 1 << '\n';
		}
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iostream>

using namespace std;
int n;
vector<int> vec;
vector<int> poloska;
int maxx;
int pos;
int counter;

void check() {
	for (int i = 0; i < 1e7; i++) {
		if (i == pos) continue;

		if (poloska[i] == maxx) {
			counter += poloska[i] - 1;
		}
		else counter += poloska[i];
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int times;
	cin >> times;
	for (int i = 0; i < times; i++) {
		cin >> n;
		maxx = 0;
		pos = 0;
		counter = 0;
		poloska = vector<int>(1e7);

		for (int i = 0; i < n; i++) {
			int now;
			cin >> now;
			poloska[now]++;
			if (poloska[now] > maxx) {
				maxx = poloska[now];
				pos = now;
			}
			vec.push_back(now);
		}
		check();
		cout << counter / (maxx - 1) << '\n';

		poloska.clear();
		vec.clear();

	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iostream>

using namespace std;
int n;
vector<int> vec;
vector<int> poloska;
int maxx;
int pos;
int counter;

void check() {
	for (int i = 0; i < 1e5+100; i++) {
		if (i == pos) continue;

		if (poloska[i] == maxx) {
			counter += poloska[i] - 1;
		}
		else counter += poloska[i];
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int times;
	cin >> times;
	for (int i = 0; i < times; i++) {
		cin >> n;
		maxx = 0;
		pos = 0;
		counter = 0;
		poloska = vector<int>(1e6);

		for (int i = 0; i < n; i++) {
			int now;
			cin >> now;
			poloska[now]++;
			if (poloska[now] > maxx) {
				maxx = poloska[now];
				pos = now;
			}
			vec.push_back(now);
		}
		check();
		cout << counter/(maxx-1) << '\n';

		poloska.clear();
		vec.clear();

	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iostream>

using namespace std;
int n;
vector<int> vec;
vector<int> poloska;
int maxx;
int pos;
int counter;

void check() {
	for (int i = 0; i < 1e7+100; i++) {
		if (i == pos) continue;

		if (poloska[i] == maxx) {
			counter += poloska[i] - 1;
		}
		else counter += poloska[i];
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int times;
	cin >> times;
	for (int i = 0; i < times; i++) {
		cin >> n;
		maxx = 0;
		pos = 0;
		counter = 0;
		poloska = vector<int>(1e6);

		for (int i = 0; i < n; i++) {
			int now;
			cin >> now;
			poloska[now]++;
			if (poloska[now] > maxx) {
				maxx = poloska[now];
				pos = now;
			}
			vec.push_back(now);
		}
		check();
		cout << counter/(maxx-1) << '\n';

		poloska.clear();
		vec.clear();

	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iostream>

using namespace std;
int n;
vector<int> vec;
vector<int> poloska;
int maxx;
int pos;
int counter;

void check() {
	for (int i = 0; i < 1e6+100; i++) {
		if (i == pos) continue;

		if (poloska[i] == maxx) {
			counter += poloska[i] - 1;
		}
		else counter += poloska[i];
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int times;
	cin >> times;
	for (int i = 0; i < times; i++) {
		cin >> n;
		maxx = 0;
		pos = 0;
		counter = 0;
		poloska = vector<int>(1e6);

		for (int i = 0; i < n; i++) {
			int now;
			cin >> now;
			poloska[now]++;
			if (poloska[now] > maxx) {
				maxx = poloska[now];
				pos = now;
			}
			vec.push_back(now);
		}
		check();
		cout << counter/(maxx-1) << '\n';

		poloska.clear();
		vec.clear();

	}
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,tune=native")
#pragma GCC target("avx,avx2")

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <cassert>
#include <cmath>
using namespace std;
const double PI = 3.141592653589793;

template < template <typename> class Array, typename T >
void outSet(Array<T>& a) {
	auto it = a.begin();
	for (; it != a.end(); it++) {
		cout << (*it) << " ";
	}
	cout << "\n";
}

template<typename T>
void outVector(vector<T>& a) {
	for (int i = 0; i < a.size(); i++) {
		cout << a[i] << " ";
	}
	cout << "\n";
}

typedef long long ll;

ll mod = 1e9 + 7;

bool check(int n, int m, vector<int> freq) {
	vector<int> ans(n, 0);
	set<pair<int, int>> q;
	for (int i = 0; i < freq.size(); i++) {
		if (freq[i] > 0)
			q.insert({ freq[i], i });
	}

	for (int i = 0; i < n; i++) {
		if (i >= m && freq[ans[i - m]] > 0) {
			q.insert({ freq[ans[i - m]], ans[i - m] });
		}
		if (q.size() == 0) {
			return 0;
		}
		ans[i] = (--q.end())->second;
		freq[ans[i]]--;
		q.erase(--q.end());
	}
	return 1;
}

void solve() {
	int n;
	cin >> n;
	vector<int> a(n), freq(1e5 + 1, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		freq[a[i]]++;
	}

	int l = 1, r = 1e9;
	while (l < r - 1) {
		int m = (l + r) / 2;
		if (check(n, m, freq)) {
			l = m;
		}
		else {
			r = m;
		}
	}
	cout << l - 1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <cassert>
#include <cmath>
using namespace std;
const double PI = 3.141592653589793;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,tune=native")
#pragma GCC target("avx,avx2")

template < template <typename> class Array, typename T >
void outSet(Array<T>& a) {
	auto it = a.begin();
	for (; it != a.end(); it++) {
		cout << (*it) << " ";
	}
	cout << "\n";
}

template<typename T>
void outVector(vector<T>& a) {
	for (int i = 0; i < a.size(); i++) {
		cout << a[i] << " ";
	}
	cout << "\n";
}

typedef long long ll;

ll mod = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> cnt(1e5 + 1, 0);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	int maxFreq = *max_element(cnt.begin(), cnt.end());

	int once = 0;
	for (int i = 0; i < 1e5 + 1; i++) {
		once += (cnt[i] == 1);
	}

	if (maxFreq == 2) {
		cout << once + (n - once) / 2 - 1 << "\n";
	}
	else {
		cout << (n - maxFreq) / (maxFreq - 1) << "\n";
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <cassert>
#include <cmath>
using namespace std;
const double PI = 3.141592653589793;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,tune=native")
#pragma GCC target("avx,avx2")

template < template <typename> class Array, typename T >
void outSet(Array<T>& a) {
	auto it = a.begin();
	for (; it != a.end(); it++) {
		cout << (*it) << " ";
	}
	cout << "\n";
}

template<typename T>
void outVector(vector<T>& a) {
	for (int i = 0; i < a.size(); i++) {
		cout << a[i] << " ";
	}
	cout << "\n";
}

typedef long long ll;

ll mod = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> cnt(1e5 + 1, 0);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	int maxFreq = *max_element(cnt.begin(), cnt.end());

	int once = 0;
	for (int i = 0; i < 1e5 + 1; i++) {
		once += (cnt[i] == 1);
	}

	if (maxFreq == 2) {
		cout << once + (n - once) / 2 - 1 << "\n";
	}
	else {
		int num = 0;
		for (int i = 0; i < 1e5 + 1; i++) {
			if (cnt[i] == maxFreq) {
				num++;
			}
		}
		if (num > (n - maxFreq) / (maxFreq - 1)) {
			cout << n / maxFreq - 1 << "\n";
		}
		else {
			cout << (n - maxFreq) / (maxFreq - 1) << "\n";
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <memory>
#include <algorithm>

using namespace std;

int main() {
	int T;
	cin >> T;
	for (int t = 0; t < T; t++) {
		int N;
		cin >> N;
		map<int, int> mp;
		for (int i = 0; i < N; i++) {
			int a;
			cin >> a;
			if (mp.find(a) == mp.end())
				mp.insert({ a, 1 });
			else
				mp[a] = mp[a] + 1;
		}
		int mx = -1;
		int cnt = 0;
		for (const auto & p : mp) {
			if (p.second > mx) {
				mx = p.second;
				cnt = 1;
			}
			else if (p.second == mx) {
				cnt++;
			}
		}
		int res = (N - cnt) / (mx - 1) - 1;
		cout << res << "\n";
	}
	return 0;
}


#include <algorithm>
#include <iostream>
#include <map>

int main() {
	std::cin.tie(nullptr);
	int T;
	std::cin >> T;
	for (int i = 0; i < T; ++i) {
		int n;
		std::cin >> n;

		std::map<int, int> typeToCount;
		for (int i = 0; i < n; ++i) {
			int a;
			std::cin >> a;
			++typeToCount[a];
		}
		int maxCount = 0;
		for (const auto& x : typeToCount) {
			maxCount = std::max(maxCount, x.second);
		}
		int separatorCount = 0;
		for (const auto& x : typeToCount) {
			if (x.second == maxCount) {
				separatorCount += maxCount - 1;
			}
			else {
				separatorCount += x.second;
			}
		}
		std::cout << separatorCount / (maxCount - 1)  - 1 << "\n";
	}
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
long aa[100010];
int main()
{
    long t;
    scanf("%ld", &t);
    while(t--){
        long n;
        scanf("%ld", &n);
        memset(aa, 0, sizeof(aa));
        for(long i = 0; i < n; i++){
            long a;
            scanf("%ld", &a);aa[a]++;
        }
        sort(aa + 1, aa + n + 1);
        //for(int i = 1; i <= n; i++)cout<<aa[i]<<' ';cout<<endl;
        long num = 1;
        for(long i = n - 1; i > 0; i--){
            if(aa[i] == aa[i + 1]){
                num++;
            }
            else{
                break;
            }
        }//cout<<aa[n - 1]<<' '<<n<<' '<<num<<endl;
        printf("%ld\n", (n - num * aa[n]) / (aa[n] - 1) + num - 1);
    }
}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		vector<int> A(2 * n, 0);
		for (int i = 0; i < n; i++) {
			int t;
			cin >> t;
			A[t] += 1;
		}

		sort(A.rbegin(), A.rend());

		int same = 0;
		for (int i = 0; i <= n; i++) {
			if (A[i] != A[0]) {
				same = i - 1;
				break;
			}
		}

		for (int dis = n; dis > 0; dis--) {
			if ((A[0] - 1) * dis + 1 > n) continue;
			if (((A[0]) * (dis) + 1) > n && (n - (dis * (A[0]-1) + 1)) <same) {
				continue;
			}
			cout << dis - 1 << '\n';
			break;

		}

	}

}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		vector<int> A(2 * n, 0);
		for (int i = 0; i < n; i++) {
			int t;
			cin >> t;
			A[t] += 1;
		}

		sort(A.rbegin(), A.rend());

		int same = 0;
		for (int i = 0; i <= n; i++) {
			if (A[i] != A[0]) {
				same = i - 1;
				break;
			}
		}

		for (int dis = n; dis > 0; dis--) {
			if ((A[0] - 1) * (long long)dis + 1 > n) continue;
			if (n - (dis * (A[0]-1) + 1) <same) {
				continue;
			}
			cout << dis - 1 << '\n';
			break;

		}

	}

}


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		vector<int> A(2 * n, 0);
		for (int i = 0; i < n; i++) {
			int t;
			cin >> t;
			A[t] += 1;
		}

		sort(A.rbegin(), A.rend());

		int same = 0;
		for (int i = 0; i <= n; i++) {
			if (A[i] != A[0]) {
				same = i - 1;
				break;
			}
		}

		for (int dis = n; dis > 0; dis--) {
			if ((A[0] - 1) * dis + 1 > n) continue;
			if (n - (dis * (A[0]-1) + 1) <same) {
				continue;
			}
			cout << dis - 1 << '\n';
			break;

		}

	}

}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 2e5 + 111;
int n;
int cnt[maxn];
int list[maxn];
int ans[maxn];
bool bml(int a, int b) {
	return a > b;
}

int jude(int x) {//间距x
	int len = 1;
	for (int i = 0; i <= n; i++) ans[i] = 0;

	for (int i = 1; i <= n; i++) {
		if (cnt[i]) {//把i放进ans
			int t = cnt[i];

			for (int j = len; j <= n ; j += x + 1) {
				ans[j] = i;
				t--;
				if (t == 0) break;
			}
			len++;
			if (t) return 0;
		}
	}

	return 1;
}

int main() {
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 0; i <= n; i++) {
			cnt[i] = 0;
		}

		for (int i = 1; i <= n; i++) {
			cin >> list[i];
			cnt[list[i]]++;
		}

		sort(cnt + 1, cnt + n + 1, bml);

		int l = 0, r = n;
		int cns = 0;
		while (l <= r) {
			int mid = l + r >> 1;
			if (jude(mid)) {
				cns = mid;
				l = mid + 1;
			}
			else {
				r = mid - 1;
			}
		}

		cout << cns << endl << endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 2e5 + 111;
int n;
int cnt[maxn];
int list[maxn];
int ans[maxn];
bool bml(int a, int b) {
	return a > b;
}

int jude(int x) {//间距x
	int len = 1;
	for (int i = 0; i <= n; i++) ans[i] = 0;

	for (int i = 1; i <= n; i++) {
		if (cnt[i]) {//把i放进ans
			int t = cnt[i];

			for (int j = len; j <= n ; j += x + 1) {
				ans[j] = i;
				t--;
				if (t == 0) break;
			}
			len++;
			if (t) return 0;
		}
	}

	return 1;
}

int main() {
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 0; i <= n; i++) {
			cnt[i] = 0;
		}

		for (int i = 1; i <= n; i++) {
			cin >> list[i];
			cnt[list[i]]++;
		}

		sort(cnt + 1, cnt + n + 1, bml);

		int l = 0, r = n;
		int cns = 0;
		while (l < r) {
			int mid = l + r >> 1;
			if (jude(mid)) {
				cns = mid;
				l = mid + 1;
			}
			else {
				r = mid - 1;
			}
		}

		cout << cns << endl << endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 2e5 + 111;
int n;
int cnt[maxn];
int list[maxn];
int ans[maxn];
bool bml(int a, int b) {
	return a > b;
}

int jude(int x) {//间距x
	int len = 1;
	for (int i = 0; i <= n; i++) ans[i] = 0;

	for (int i = 1; i <= n; i++) {
		if (cnt[i]) {//把i放进ans
			int t = cnt[i];

			for (int j = len; j <= n ; j += x + 1) {
				ans[j] = i;
				t--;
				if (t == 0) break;
			}
			len++;
			if (t) return 0;
		}
	}

	return 1;
}

int main() {
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 0; i <= n; i++) {
			cnt[i] = 0;
		}

		for (int i = 1; i <= n; i++) {
			cin >> list[i];
			cnt[list[i]]++;
		}

		sort(cnt + 1, cnt + n + 1, bml);

		int l = 0, r = n;
		int cns = 0;
		for(int i=0;i<101;i++){
			int mid = l + r >> 1;
			if (jude(mid)) {
				cns = mid;
				l = mid + 1;
			}
			else {
				r = mid - 1;
			}
		}

		cout << cns << endl << endl;
	}
	return 0;
}


#include <iostream>
#include<vector>
#include <algorithm>
#include<string>
#include <set>
#include<map>
#include <string.h>
using namespace std;
void help2(map<int, int>& m2) {
	bool p_s = false;
	bool p_r1 = false;
	bool p_r2 = false;
	for (auto it = m2.begin(); it != m2.end(); it++) {
		int qun = it->first;
		int num = it->second;
		if (qun >= 2 && qun <= 3) {
			if (num == 1) {
				if (p_r1 == false) {
					p_r1 = true;
				}
				else {
					p_r2 = true;
				}
			}
			else if (num > 1) {
				p_r1 = true;
				p_r2 = true;
			}
		}
		else if (qun >= 4 && qun <=5) {
			if (num == 1) {
				if (p_s == false) {
					p_s = true;
				}
				else {
					p_r1 = true;
					p_r2 = true;
				}
			}
			else if (num>1){
				p_s = true;
				p_r1 = true;
				p_r2 = true;
			}
		}
		else if (qun >= 6 && qun <= 7) {
			if (num == 1) {
				if (p_s == false) {
					p_s = true;
					if (p_r1 == false) {
						p_r1 = true;
					}
					else {
						p_r2 = true;
					}
				}
				else {
					p_r1 = true;
					p_r2 = true;
				}
			}
			else if (num > 1) {
				p_s = true;
				p_r1 = true;
				p_r2 = true;
			}
		}
		else if (qun == 8) {
			if (num >= 1) {
				p_s = true;
				p_r1 = true;
				p_r2 = true;
			}
		}
		if (p_s == true && p_r1 == true && p_r2 == true) {
			cout << "YES" << endl;
			return;
			break;
		}
	}
	cout << "NO" << endl;
	return;
}
void help(map<int, int>& m2) {
	int tot = 0;
	int l_q;
	int l_size;
	int flag = 1;
	for (auto i = m2.rbegin(); i != m2.rend(); ++i) {
		int q = i->first;
		int n = i->second;
		if (flag == 1) {
			l_q = n;
			l_size = q;
			flag = 0;
		}
		else {
			tot = tot + q * n;
		}
	}
	if (l_size == 1) {
		cout<<"1"<<endl;
		return;
	}
	int ans = (l_q - 1) + (tot) / (l_size - 1);
	cout << ans << endl;
	return;
}

void solve() {
	int n;
	cin >> n;
	map<int, int>m;
	map<int, int>m2;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		int qun = m[t];
		//if (qun <= 8) {
			if (m2.find(qun) != m2.end()) {
				m2[qun]--;
			}
		//}

		m[t]++;
	 qun = m[t];
		//if (qun <= 8) {
			m2[qun]++;
		//}

	}

		help(m2);

	//cout << (n / 2) + 1 << endl;
	return;

}

int main() {
	int t;
	cin >> t;
	//int num = t;
	while (t--)
	{
		//cout << "Case #" << num-t << ":" << endl;
		solve();
	}
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef int Int;

vector<Int> a;
vector<Int> freq;

void solve(Int n)
{
	int maxfreq = 0; // max of all the freqs
	int maxfreq_count = 0; // number of occurences of maxfreq

	for (int k = 1; k <= n; k++)
	{
		if (freq[k] > maxfreq)
		{
			maxfreq = freq[k];
			maxfreq_count = 1;
		}
		else if (freq[k] == maxfreq)
		{
			maxfreq_count++;
		}
	}

	int ans = (n - maxfreq_count)/(maxfreq - 1) - 1;
	cout << ans << endl;
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	std::ifstream in("inputC.txt");
	std::cin.rdbuf(in.rdbuf()); //redirect std::cin to input.txt!

	std::ofstream out("outC.txt");
	std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
#endif

	int t;
	cin >> t;
	while (t--) {
		Int n;
		cin >> n;
		a = vector<Int>(n);
		freq = vector<Int>(n+1);
		for (Int i=0; i<n; ++i)
		{
			cin >> a[i];
			freq[a[i]]++;
		}
		solve(n);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
const int max_n = 1e5 + 100;
int a[max_n];
int b[max_n];
int n;

int main() {
	ios::sync_with_stdio(0);
	int t;cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1;i <= n;++i)cin >> a[i];
		for (int i = 1;i <= n;++i)b[i] = 0;
		for (int i = 1;i <= n;++i)++b[a[i]];
		int ma = 0;
		for (int i = 1;i <= n;++i)ma = max(ma, b[i]);
		int cnt1 = 0, cnt2 = 0;
		for (int i = 1;i <= n;++i)
			if (b[i] == ma)cnt2 += b[i];
			else cnt1 += b[i];
		cnt2 -= ma;
		int ans = 0;
		ans += cnt1 / (ma - 1);
		int ex = cnt1 % (ma - 1);
		ans += (cnt2 + ex) / ma;
		cout << ans << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

bool cmp(int a, int b) {
	if (a >= b)return true;
	else return false;
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		ll n;
		cin >> n;
		vector<ll>arr(100001, 0);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			arr[a]++;
		}

		sort(arr.begin(), arr.end(),cmp);

		ll ans = 0;
		for (int i = 0; i < n; i++) {
			if (arr[i] == arr[0]) {
				ans++;
				n -= arr[0];
			}
			else break;
		}
		ans += n / (arr[0] - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		int n, mx = 0; cin >> n;
		vector<pair<int, int>> v(100001);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			v[a] = { v[a].first + 1, a };
			mx = max(mx, v[a].first);
		}

		sort(v.begin(), v.end(), greater<pi>());

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (v[i].first == mx) {
				ans++;
				n -= mx;
			}
			else break;
		}
		ans += n / (mx - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

bool cmp(pair<int, int> a, pair<int, int>b) {
	if (a.first > b.first)return true;
	else if(a.first < b.first) return false;
	else return a.second < b.second;
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		int n, mx = 0; cin >> n;
		vector<pair<int, int>> v(100001);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			v[a] = { v[a].first + 1, a };
			mx = max(mx, v[a].first);
		}

		sort(v.begin(), v.end(), cmp);

		int ans = 0;
		for (const auto &i : v)
			if (i.first == mx) {
				ans++;
				n -= i.first;
			}

		ans += n / (mx - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

bool cmp(int a, int b) {
	if (a >= b)return true;
	else return false;
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		ll n;
		cin >> n;
		vector<ll>arr(100001, 0);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			arr[a]++;
		}

		sort(arr.begin(), arr.end(),cmp);

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (arr[i] == arr[0]) {
				ans++;
				n -= arr[0];
			}
			else break;
		}
		ans += n / (arr[0] - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

bool cmp(int a, int b) {
	if (a >= b)return true;
	else return false;
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		int n, mx = 0; cin >> n;
		vector<int>arr(100001, 0);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			arr[a]++;
		}

		sort(arr.begin(), arr.end(),cmp);

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (arr[i] == arr[0]) {
				ans++;
				n -= arr[0];
			}
			else break;
		}
		ans += n / (arr[0] - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		int n, mx; cin >> n;
		vector<int>arr(100001, 0);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			arr[a]++;
		}

		sort(arr.begin(), arr.end());

		mx = arr[100000];
		int ans = 0;
		for (auto i : arr) {
			if (arr[i] == mx) {
				ans++;
				n -= mx;
			}
		}
		ans += n / (mx - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

bool cmp(int a, int b) {
	if (a > b)return true;
	else return false;
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		int n, mx = 0; cin >> n;
		vector<pair<int, int>> v(100001);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			v[a] = { v[a].first + 1, a };
			mx = max(mx, v[a].first);
		}

		sort(v.begin(), v.end(), greater<pi>());

		int ans = 0;
		for (const auto &i : v)
			if (i.first == mx) {
				ans++;
				n -= i.first;
			}

		ans += n / (mx - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

bool cmp(int a, int b) {
	if (a > b)return true;
	else return false;
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		int n, mx = 0; cin >> n;
		vector<pi>v(100001);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			v[a] = { v[a].first + 1, a };
			mx = max(mx, v[a].first);
		}

		sort(v.begin(), v.end(), greater<pi>());

		int ans = 0;
		for (const auto &i : v)
			if (i.first == mx) {
				ans++;
				n -= i.first;
			}

		ans += n / (mx - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <bits/stdc++.h>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

bool cmp(int a, int b) {
	if (a > b)return true;
	else return false;
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		int n, mx = 0; cin >> n;
		vector<pair<int, int>> v(100001);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			v[a] = { v[a].first + 1, a };
			mx = max(mx, v[a].first);
		}

		sort(v.begin(), v.end(), greater<>());

		int ans = 0;
		for (const auto &i : v)
			if (i.first == mx) {
				ans++;
				n -= i.first;
			}

		ans += n / (mx - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

bool cmp(int a, int b) {
	if (a > b)return true;
	else return false;
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		ll n;
		cin >> n;
		vector<ll>arr(100001, 0);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			arr[a]++;
		}

		sort(arr.begin(), arr.end(),cmp);

		ll ans = 0;
		for (int i = 0; i < n; i++) {
			if (arr[i] == arr[0]) {
				ans++;
				n -= arr[0];
			}
			else break;
		}
		ans += n / (arr[0] - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1 };
int dy[] = { 0, 1, 0, -1, -1, 1, -1, 1 };

//----------------------------------------------------

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int t, n, a, mx;

	cin >> t;
	while (t--) {
		cin >> n;
		mx = 0;
		map<int, int>m;
		map<int, int>::iterator it;
		for (int i = 0; i < n; i++) {
			cin >> a;
			it = m.find(a);
			if (it == m.end()) {
				m.insert(pi(a, 1));
				mx = max(1, mx);
			}
			else {
				it->second++;
				mx = max(it->second, mx);
			}
		}

		int ans = -1;
		for (auto i : m) {
			if (i.second == mx) {
				ans++;
				n -= mx;
			}
		}
		ans += (n / (mx-1));

		cout << ans << '\n';

	}

	return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

#define INF 987654321

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pair<int, int>>ppi;
typedef unsigned int ui;
typedef long long ll;

int dx[] = { -1, 1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

//----------------------------------------------------

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T; cin >> T;
	while (T--) {
		int n, mx = 0; cin >> n;
		vector<pair<int, int>> v(100001);
		for (int i = 0; i < n; i++) {
			int a; cin >> a;
			v[a] = { v[a].first + 1, a };
			mx = max(mx, v[a].first);
		}

		sort(v.begin(), v.end(), greater<>());

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (v[i].first == mx) {
				ans++;
				n -= mx;
			}
			else break;
		}
		ans += n / (mx - 1) - 1;
		cout << ans << "\n";
	}

	return 0;

}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<stack>
#include<chrono>
#include<random>
#include<cerrno>
#include<cfenv>

typedef long long int lli;
typedef long long ll;
typedef double long dl;
using namespace std;

const int mod = 1000000007;
const dl pi = std::acos(-1);

ll gcd(ll a, ll b) {
	if (!b) {
		return a;
	}
	return gcd(b, a % b);
}

ll gcdE(ll a, ll b, ll* x, ll* y) {
	if (!a) {
		*x = 0;
		*y = 1;
		return b;
	}
	ll x1, y1;
	ll _gcd = gcdE(b % a, a, &x1, &y1);
	*x = y1 - (b / a) * x1;
	*y = x1;
	return _gcd;
}

ll power(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y & 1) {
			res = (res * x) % mod;
		}
		y >>= 1;
		x = (x * x) % mod;
	}
	return res;
}

ll inverse(ll x) {
	return power(x, mod - 2);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<ll>a(n);
		map<ll, ll>f;
		ll cur = 0;
		for (int i = 0; i < n; i += 1) {
			cin >> a[i];
			f[a[i]] += 1;
		}
		ll maxx = -1;
		for (auto x : f) {
			cur += x.second;
			if (x.second > maxx) {
				maxx = x.second;;
			}
		}
		ll count = -1;
		for (auto x : f) {
			if (x.second == maxx) {
				cur -= maxx;
				count += 1;
			}
		}
		maxx -= 1;
		ll ans = cur / maxx;
		cout << ans + count << "\n";
	}
}


#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#include <fstream>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INF2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

using namespace std;

//#define DEBUG
#ifndef DEBUG
#define in cin
#define out cout
#endif

bool solve(int two, int four, int six, int eight)
{
	if (four == 0) return false;
	if (eight >= 1) return true;
	if (six >= 1 && two >= 2) return true;
	if (four >= 1 && two >= 3) return true;
	if (four >= 2) return true;
	return false;
}

int main()
{
#ifdef DEBUG
	ifstream in("input.txt");
	ofstream out("output.txt");
#endif

	in.tie(NULL);
	out.tie(NULL);
	ios_base::sync_with_stdio(false);
	int testcase=1;
	in >> testcase;
	while (testcase--)
	{
		int nums[100001] = {0,};
		int n, tmp, maxnum=0, countmax=0;
		in >> n;
		for (int i = 0; i < n; i++)
		{
			in >> tmp;
			nums[tmp]++;
			maxnum = max(maxnum, nums[tmp]);
		}
		for (int i = 1; i <= 100000; i++)
		{
			if (nums[i] == maxnum) countmax++;
		}
		int m = n - countmax;
		int k = m / (maxnum - 1);
		out << k - 1 << endl;
	}
	return 0;
}


#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<queue>
#define LL long long
using namespace std;
const int maxn = 100005;
const int mod = 1e9+7;
int a[maxn];
int main(){
    int T, n, x;
    scanf("%d",&T);
    while(T--){
        scanf("%d", &n);
        memset(a, 0, sizeof(a));
        int maxx = 0, ci = 0;
        for (int i = 0; i < n; i++){
            scanf("%d", &x);
            a[x]++;
            if(a[x] > maxx){
                maxx = a[x];
                ci = 1;
            } else if (a[x] == maxx){
                ci++;
            }
        }
        int ans = (n - maxx) / (maxx - 1);
        int yu = n - maxx - (maxx - 1) * ans;
        if (ci <= yu + 1){
            printf("%d\n", ans);
        } else {
            if ((ci - yu - 1) % (maxx - 1) == 0){
                printf("%d\n", ans - (ci - yu - 1) / (maxx - 1)); //刚好
            } else {
                printf("%d\n", ans - (ci - yu - 1) / (maxx - 1) - 1); //多移动一位
            }
        }
    }
    return 0;
}


#include<stdio.h>
const int maxn=100010;
int cnt[maxn],m;
int main()
{
	int t,c,a,ans,n;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
				cnt[i]=0;
		}
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a);
			cnt[a]++;
		}
		c=0;
		for(int i=1;i<=n;i++)
			if(c<cnt[i])
			{
				c=cnt[i];
				m=1;
			}
			else if(c==cnt[i])
			m++;
			ans=(n-m*c)/(c-1)+m-1;
		printf("%d\n",ans);
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define Iii pair < int, ii >
#define LL pair < ll, ll >
#define INF 1000000007
#define LINF 1000000000000000007

#define data pair < ll, ll >
#define p_q priority_queue < data >
#define np_q priority_queue < data, vector < data >, greater < data > >

int arr[100005];
int nums[1000005];

int main()
{
	int t;
	scanf("%d", &t);

	while (t--)
	{
		memset(arr, 0, sizeof(arr));
		memset(nums, 0, sizeof(arr));

		int n;
		scanf("%d", &n);

		nums[0] = n;

		int ma = 0;
		for (int i = 0; i < n; i++)
		{
			int inp;
			scanf("%d", &inp);

			nums[arr[inp]]--;
			arr[inp]++;
			nums[arr[inp]]++;

			ma = max(ma, arr[inp]);
		}

		int ans = nums[ma] - 1;
		n -= nums[ma] * ma;

		ans += n / (ma - 1);

		printf("%d\n", ans);
	}
}


#pragma comment(linker, "/STACK:628777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
using namespace std;

#define forx(_name,_from, to, value) for (int name = from; name < to; name += value)
#define rforx(_name, from, to, value) for (int name = from; name > to; name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST,_SECOND)

typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-9;
mt19937 rndm;

void start()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(6); cout.setf(ios::fixed);
	rndm.seed(time(0));
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

const int MAX_N = 1e5 + 7;
const int MAX_M = 5e5 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;

int cnt[MAX_N];
pair <int, int> a[MAX_N];

bool cmp(int v1, int v2)
{
	return v1 > v2;
}

void solve()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		x--;
		cnt[x]++;
	}
	sort(cnt, cnt + n, cmp);
	int ans = INF;
	while (cnt[0] != 0)
	{
		int i = 0;
		while (cnt[i] != 0)
			cnt[i++]--;
		if (cnt[0] == 0)
			break;
		ans = min(ans, max(0, i - 1));
	}
	printf("%d\n", ans);
}

void multitest()
{
	int t;
	cin >> t;
	for (int i = 1; i <= t; i++)
	{
		solve();
	}
}

int main() {
	start();
	multitest();
	//solve();
	//system("pause");
	return 0;
}


#pragma comment(linker, "/STACK:628777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
using namespace std;

#define forx(_name,_from, to, value) for (int name = from; name < to; name += value)
#define rforx(_name, from, to, value) for (int name = from; name > to; name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST,_SECOND)

typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-9;
mt19937 rndm;

void start()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(6); cout.setf(ios::fixed);
	rndm.seed(time(0));
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

const int MAX_N = 1e5 + 7;
const int MAX_M = 5e5 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;

int cnt[MAX_N];
pair <int, int> a[MAX_N];

bool cmp(int v1, int v2)
{
	return v1 > v2;
}

void solve()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		x--;
		cnt[x]++;
	}
	sort(cnt, cnt + n, cmp);
	int cnt_1 = 0;
	for (int i = 0; i < n; i++)
	{
		if (cnt[i] == 1)
		{
			cnt_1++;
			cnt[i] = 0;
		}
	}
	vector <int> answers;
	while (cnt[0] != 0)
	{
		int i = 0;
		while (cnt[i] != 0)
			cnt[i++]--;
		if (cnt[0] == 0)
			break;
		answers.push_back(max(0, i - 1));
	}
	int ans = INF;
	sort(answers.begin(), answers.end());
	answers.push_back(INF);
	while (cnt_1 != 0)
	{
		int l = 0, r = 1;
		while (r < n && answers[r - 1] == answers[r])
			r++;
		while (answers[r - 1] != answers[r] && cnt_1 != 0)
		{
			for (int i = 0; i < r && cnt_1 > 0; i++)
			{
				answers[i]++;
				cnt_1--;
			}
		}
	}
	for (auto cur_ans : answers)
		ans = min(cur_ans, ans);
	printf("%d\n", ans);
}

void multitest()
{
	int t;
	cin >> t;
	for (int i = 1; i <= t; i++)
	{
		solve();
	}
}

int main() {
	start();
	multitest();
	//solve();
	//system("pause");
	return 0;
}


#pragma comment(linker, "/STACK:628777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
using namespace std;

#define forx(_name,_from, to, value) for (int name = from; name < to; name += value)
#define rforx(_name, from, to, value) for (int name = from; name > to; name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST,_SECOND)

typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-9;
mt19937 rndm;

void start()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(6); cout.setf(ios::fixed);
	rndm.seed(time(0));
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

const int MAX_N = 1e5 + 7;
const int MAX_M = 5e5 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;

int cnt[MAX_N];
pair <int, int> a[MAX_N];

bool cmp(int v1, int v2)
{
	return v1 > v2;
}

void solve()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		cnt[i] = 0;
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		x--;
		cnt[x]++;
	}
	sort(cnt, cnt + n, cmp);
	int r = 1;
	while (r < n && cnt[r] == cnt[r - 1])
		r++;
	int ans = r - 1;
	int k = cnt[0] - 1;
	int sum = 0;
	while (r < n && cnt[r] != 0)
		sum += cnt[r++];
	ans += sum / k;
	printf("%d\n", ans);
}

void multitest()
{
	int t;
	cin >> t;
	for (int i = 1; i <= t; i++)
	{
		solve();
	}
}

int main() {
	start();
	multitest();
	//solve();
	//system("pause");
	return 0;
}


#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<map>
#include<assert.h>
#include<time.h>
#include<stdlib.h>
#include<random>
#include<queue>
using namespace std;
using lld = long long int;
using pll = pair<lld, lld>;
using plll = pair<lld, pll>;
using lf = double;
using pff = pair<lf, lf>;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
using pili = pair < pil, int>;
int n, m;
int a[200009];
int b[200009];
bool valid(int x) {
	if (x >= n)return true;
	int mm = n / x;
	int rem = n % x;
	int rr = n - rem;
	//rem need mm+1
	//rr need mm
	//printf("%d %d %d  %d %d\n", x, mm, rem, b[mm+2], b[mm+1]);
	if (b[mm + 2] > 0)return false;
	return b[mm + 1] <= rem;
}
int main() {
	int i, j, k, l;
	int t = 1, tv = 0;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (i = 0; i <= n + 5; i++) {
			a[i] = 0;
			b[i] = 0;
		}
		for (i = 0; i < n; i++) {
			scanf("%d", &j);
			a[j]++;
		}
		m = 0;
		for (i = 1; i <= n; i++) {
			b[a[i]]++;
			m = max(m, a[i]);
		}
		for (i = n - 1; i >= 0; i--) {
			b[i] += b[i + 1];
		}
		int l = 2;
		int r = n;
		while (l < r) {
			int mid = (l + r) / 2;
			if (valid(mid)) {
				l = mid + 1;
			}
			else r = mid;
		}
		printf("%d\n", l - 2);
	}
	return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;

bool check(unordered_set<int> &pairs, unordered_set<int> &cubes, unordered_map<int, int> &d) {
    if (cubes.size() == 0) {
        return false;
    }
    if (cubes.size() >= 2) {
        return true;
    }
    int kek = 0;
    if (d[*cubes.begin()] >= 8) {
        return true;
    }
    if (d[*cubes.begin()] >= 6) {
        kek++;
    }
    return pairs.size() + kek >= 2;
}

void solve() {
    int n;
    unordered_map<int, int> d;
    d.reserve(200000);
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        d[x] = d[x] + 1;
    }
    int maxx = 0, cnt;
    for (auto x: d) {
        if (x.second == maxx) {
            cnt++;
        }
        if (x.second > maxx) {
            maxx = x.second;
            cnt = 1;
        }
    }
    int holes = maxx - 1;
    int rem = n - cnt * maxx;
    int ans = cnt - 1 + rem / holes;
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false);
	int t, n, r, m, h1;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n;
		vector <int> a(n), c(n + 1, 0);
		m = -1;
		for (int j = 0; j < n; j++) {
			cin >> a[j];
			c[a[j]]++;
			m = max(m, c[a[j]]);
		}
		h1 = 0;
		for (int j = 1; j <= n; j++) {
			if (c[j] == m)
				h1++;
		}
		r = (n - m * h1) / (m-1);
		cout << r + h1 - 1 << "\n";
	}
}


#include<cstdio>
#include<iostream>
#include<map>

using namespace std;

const int N = 1e5+5;

int a[N];

int main()
{
	int t;

	scanf("%d",&t);

	while(t--)
	{
		int n;

		scanf("%d",&n);

		map<int,int> mp;

		int maxnum = -1, apptime=0;

		for(int i=1;i<=n;++i)
		{
			scanf("%d",&a[i]);

			++mp[a[i]];

			if(mp[a[i]]>maxnum)
			{
				maxnum = mp[a[i]];

				apptime = 1;
			}
			else
			if(mp[a[i]]==maxnum)
			{
				++apptime;
			}
		}

		if(apptime==1)
		{
			int ansnum = (n - maxnum)/(maxnum-1);

			printf("%d\n",ansnum);
		}
		else
		{
			int ansnum = (n - maxnum - apptime + 1)/(maxnum-1);

			printf("%d\n",ansnum);
		}
	}

	return 0;
 }


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

#pragma comment(linker, "/STACK:36777216")
using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

typedef long double ptype;

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
int inf = 1e9;
double eps = 1e-7;
long double pi = acosl(-1);
ifstream in("input.txt");
ofstream out("output.txt");

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n + 1, 0);
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a[t]++;
	}
	sort(a.rbegin(), a.rend());
	int l = 0, r = n;
	while (r - l > 1)
	{
		int m = (r + l) / 2;
		int p = 0;
		vector<int> b(n, -1);
		bool good = 1;
		for (int i = 0; i < n; i++)
		{
			while (p < n && b[p] != -1) p++;
			for (int j = 0; j < a[i]; j++)
			{
				if (p + j * (m + 1) >= n)
				{
					good = 0;
					break;
				}
				b[p + j * (m + 1)] = i;
			}
			if (!good) break;
		}
		if (good)
		{
			l = m;
		}
		else
		{
			r = m;
		}
	}
	cout << l << "\n";
}

int main()
{
	cout << setprecision(2) << fixed;
	cin.tie();
	cout.tie();
	//freopen("output.txt", "w", stdout);
	int t;
	cin >> t;
	//t = 1;
	while (t--) {
		solve();
	}
	gg;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

#pragma comment(linker, "/STACK:36777216")
using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

typedef long double ptype;

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
int inf = 1e9;
double eps = 1e-7;
long double pi = acosl(-1);
ifstream in("input.txt");
ofstream out("output.txt");

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n + 1, 0);
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a[t]++;
	}
	sort(a.rbegin(), a.rend());
	int res = (n - a[0]) / (a[0] -1 );
	for (int i = 1; i < n && a[i] == a[0]; i++)
	{
		res = min(res, (n - i - a[i]) / (a[i] - 1));
	}
	cout << res << "\n";
}

int main()
{
	cout << setprecision(2) << fixed;
	cin.tie();
	cout.tie();
	//freopen("output.txt", "w", stdout);
	int t;
	cin >> t;
	//t = 1;
	while (t--) {
		//gen(7);
		//int r = slow();
		/*int r1 = */solve();
	}
	gg;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

#pragma comment(linker, "/STACK:36777216")
using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

typedef long double ptype;

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
int inf = 1e9;
double eps = 1e-7;
long double pi = acosl(-1);
ifstream in("input.txt");
ofstream out("output.txt");

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n + 1, 0);
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		a[t]++;
	}
	sort(a.rbegin(), a.rend());
	int l = 0, r = n + 1;
	while (r - l > 1)
	{
		int m = (r + l) / 2;
		int p = 0;
		vector<int> b(n, -1);
		bool good = 1;
		for (int i = 0; i < n; i++)
		{
			if (a[i] <= 1) break;
			while (p < n && b[p] != -1) p++;
			for (int j = 0; j < a[i]; j++)
			{
				if (p + j * (m + 1) >= n)
				{
					good = 0;
					break;
				}
				b[p + j * (m + 1)] = i;
			}
			if (!good) break;
		}
		if (good)
		{
			l = m;
		}
		else
		{
			r = m;
		}
	}
	cout << l << "\n";
}

int main()
{
	cout << setprecision(2) << fixed;
	cin.tie();
	cout.tie();
	//freopen("output.txt", "w", stdout);
	int t;
	cin >> t;
	//t = 1;
	while (t--) {
		solve();
	}
	gg;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <utility>
#include <iterator>
#include <deque>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define pii pair <int, int>
#define pll pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define en '\n'

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(8);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector <int> a(n);
        set <pii> c;
        map <int, int> b;
        for (auto & i : a) {
            cin >> i;
            b[i]++;
        }
        for (auto i : b) {
            c.insert({i.se, i.fi});
        }
        int l = 0, r = n;
        while (r - l > 1) {
            int m = (r + l) / 2;
            bool f = true;
            set <pii> q = c;
            vector <pii> q1(n, {-1, -1});
            for (int i = 0; i < n; i++) {
                if (q1[i].fi != -1) q.insert(q1[i]);
                if (q.empty()) {
                    f = false;
                    break;
                }
                auto k = *q.rbegin();
                q.erase(k);
                if (k.fi != 1) {
                    if (i + m + 1 >= n) {
                        f = false;
                        break;
                    }
                    q1[i + m + 1] = {k.fi - 1, k.se};
                }
            }
            if (f) l = m;
            else r = m;
        }

        cout << l << en;
    }

    return 0;
}

/*
        ▄▀▀▀▀▄
        █  ▀ █▄▄
   ▄ ▄▄▄▀▄ █▀▀▀
   █▀▄  ▀▄  ▀▄
   █  ▀▀▀    █
    ▀▄▄▄▄▄▄▄▀
*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <utility>
#include <iterator>
#include <deque>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define pii pair <int, int>
#define pll pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define en '\n'

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(8);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector <int> a(n);
        deque <pii> c;
        map <int, int> b;
        for (auto & i : a) {
            cin >> i;
            b[i]++;
        }
        int x = 0;
        for (auto i : b) {
            if (i.se == 1) x++;
            else c.push_back(i);
        }
        int l = 0, r = n;
        while (r - l > 1) {
            int m = (r + l) / 2;
            bool f = true;
            deque <pii> q = c;
            map <int, int> e;
            int x1 = x, x2 = 0;
            while (!q.empty()) {
                pii k = q.front();
                q.pop_front();
                if (e[k.fi]) {
                    x1 -= e[k.fi];
                    x2 -= e[k.fi];
                    e[k.fi] = 0;
                }
                if (k.se != 1) {
                    q.push_back({k.fi, k.se - 1});
                    int d = max(0, m - (int)(q.size()) + 1);
                    if (d > x1) {
                        f = false;
                        break;
                    } else {
                        e[k.fi] = max(0, d - x2);
                        x2 += e[k.fi];
                    }
                }
            }
            if (f) l = m;
            else r = m;
        }

        cout << l << en;
    }

    return 0;
}

/*
        ▄▀▀▀▀▄
        █  ▀ █▄▄
   ▄ ▄▄▄▀▄ █▀▀▀
   █▀▄  ▀▄  ▀▄
   █  ▀▀▀    █
    ▀▄▄▄▄▄▄▄▀
*/


import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class Main {

	public static void main(String[] args)
	{

		Scanner ab=new Scanner(System.in);

		long x=ab.nextInt(),z=ab.nextInt();

		String str=ab.next();

		//long f=200000;
		//System.out.println((f*(f+1))/2);
		Set<Character>set=new TreeSet<>();
		for(int y=0;y<z;y++)set.add(ab.next().charAt(0));int sum2=0;
		int n=str.length();int sum=0;boolean b1=true;int c=0;

		int temp=0;

		char t[]=str.toCharArray();

			//	System.out.println(c);
			long index=0,div=0;long cnt=0;boolean b=true;
			for(int y=0;y<n;y++)
			{

				 if(set.contains(t[y])) {sum2++;continue;}
				 else
				{

					div=(sum2*(sum2+1))/2;
					cnt+=div;

       				sum2=0;

			    }
			}

			div=(sum2*(sum2+1))/2;
			cnt+=div;

			System.out.println(cnt);
		}

	}


import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        String str = sc.next();
        sc.nextLine();
        String c = sc.nextLine();
        int count[] = new int[n];
        for(int i = 0; i < k*2; i += 2) {
            for(int j = 0; j < n; j++) {
                if(str.charAt(j) == c.charAt(i)) {
                    count[j] = 1;
                }
            }
        }
        int ans = 0;
        int i = 0;
        while(i < n) {
            if(count[i] == 1) {
                int j = i+1;
                while(j < n && count[j] == 1) {
                    j += 1;
                }
                ans += ((j-i)*(j-i+1))/2;
                i = j;
            }
            i += 1;
        }
        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        String str = sc.next();
        sc.nextLine();
        String c = sc.nextLine();
        int count[] = new int[n];
        for(int i = 0; i < k*2; i += 2) {
            //System.out.print("i="+ i+" ");
            for(int j = 0; j < n; j++) {
                if(str.charAt(j) == c.charAt(i)) {
                    //System.out.print(str.charAt(j)+" ");
                    count[j] = 1;
                }
            }
        }
        BigInteger ans = new BigInteger("0");
        int i = 0;
        while(i < n) {
            if(count[i] == 1) {
                int j = i+1;
                while(j < n && count[j] == 1) {
                    j += 1;
                }
                long temp = ((j-i)*(j-i+1))/2;
                ans = ans.add(BigInteger.valueOf(temp));
                i = j;
            }
            i += 1;
        }
        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        String str = sc.next();
        sc.nextLine();
        String c = sc.nextLine();
        int count[] = new int[n];
        for(int i = 0; i < k*2; i += 2) {
            for(int j = 0; j < n; j++) {
                if(str.charAt(j) == c.charAt(i)) {
                    count[j] = 1;
                }
            }
        }
        BigInteger ans = new BigInteger("0");
        int i = 0;
        while(i < n) {
            if(count[i] == 1) {
                int j = i+1;
                while(j < n && count[j] == 1) {
                    j += 1;
                }
                BigInteger temp1 = BigInteger.valueOf(j-i);
                BigInteger temp2 = BigInteger.valueOf((j-i)+1);
                BigInteger temp3 = temp1.multiply(temp2);
                BigInteger temp5 = new BigInteger("2");
                BigInteger temp4 = temp3.divide(temp5);
                ans = ans.add(temp4);
                i = j;
            }
            i += 1;
        }
        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        String str = sc.next();
        sc.nextLine();
        String c = sc.nextLine();
        int count[] = new int[n];
        for(int i = 0; i < k*2; i += 2) {
            //System.out.print("i="+ i+" ");
            for(int j = 0; j < n; j++) {
                if(str.charAt(j) == c.charAt(i)) {
                    //System.out.print(str.charAt(j)+" ");
                    count[j] = 1;
                }
            }
        }
        BigInteger ans = new BigInteger("0");
        int i = 0;
        while(i < n) {
            if(count[i] == 1) {
                int j = i+1;
                while(j < n && count[j] == 1) {
                    j += 1;
                }
                int temp = ((j-i)*(j-i+1))/2;
                ans = ans.add(BigInteger.valueOf(temp));
                i = j;
            }
            i += 1;
        }
        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        String str = sc.next();
        sc.nextLine();
        String c = sc.nextLine();
        int count[] = new int[n];
        for(int i = 0; i < k*2; i += 2) {
            //System.out.print("i="+ i+" ");
            for(int j = 0; j < n; j++) {
                if(str.charAt(j) == c.charAt(i)) {
                    //System.out.print(str.charAt(j)+" ");
                    count[j] = 1;
                }
            }
        }
        long long ans = 0;
        int i = 0;
        while(i < n) {
            if(count[i] == 1) {
                int j = i+1;
                while(j < n && count[j] == 1) {
                    j += 1;
                }
                ans += ((j-i)*(j-i+1))/2;
                i = j;
            }
            i += 1;
        }
        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        String str = sc.next();
        sc.nextLine();
        String c = sc.nextLine();
        int count[] = new int[n];
        for(int i = 0; i < k*2; i += 2) {
            //System.out.print("i="+ i+" ");
            for(int j = 0; j < n; j++) {
                if(str.charAt(j) == c.charAt(i)) {
                    //System.out.print(str.charAt(j)+" ");
                    count[j] = 1;
                }
            }
        }
        long ans = 0;
        int i = 0;
        while(i < n) {
            if(count[i] == 1) {
                int j = i+1;
                while(j < n && count[j] == 1) {
                    j += 1;
                }
                ans += ((j-i)*(j-i+1))/2;
                i = j;
            }
            i += 1;
        }
        System.out.println(ans);
    }
}


import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
public final class Codeforces{
    public static void main(String[] args){
        Scanner scanner = new Scanner( System.in );
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        scanner.nextLine();
        String s= scanner.nextLine();
        string chars = scanner.nextLine();
        Set<Character> charSet = new HashSet<>();
        int index=0;
        while(k>0){
            charSet.add(chars.charAt(index));
            index+=2;
            k--;
        }
        int m=0;
        long sum=0;
        for(int i=0;i<n;i++){
            if(charSet.contains(s.charAt(i))){
                m++;
                if(i==n-1){
                    sum+=m*(m+1)/2;
                }
            }
            else if(m!=0){
                sum+=m*(m+1)/2;
                m=0;
            }
        }
        System.out.print(sum);
    }
}


import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
public final class Codeforces{
    public static void main(String[] args){
        Scanner scanner = new Scanner( System.in );
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        scanner.nextLine();
        String s= scanner.nextLine();
        String chars = scanner.nextLine();
        Set<Character> charSet = new HashSet<>();
        int index=0;
        while(k>0){
            charSet.add(chars.charAt(index));
            index+=2;
            k--;
        }
        int m=0;
        long sum=0;
        for(int i=0;i<n;i++){
            if(charSet.contains(s.charAt(i))){
                m++;
                if(i==n-1){
                    sum+=m*(m+1)/2;
                }
            }
            else if(m!=0){
                sum+=m*(m+1)/2;
                m=0;
            }
        }
        System.out.print(sum);
    }
}


import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
public final class Codeforces{
    public static void main(String[] args){
        Scanner scanner = new Scanner( System.in );
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        scanner.nextLine();
        String s= scanner.nextLine();
        String chars = scanner.nextLine();
        Set<Character> charSet = new HashSet<>();
        int index=0;
        while(k>0){
            charSet.add(chars.charAt(index));
            index+=2;
            k--;
        }
        long m=0;
        long sum=0;
        for(int i=0;i<n;i++){
            if(charSet.contains(s.charAt(i))){
                m++;
                if(i==n-1){
                    sum+=m*(m+1)/2;
                }
            }
            else if(m!=0){
                sum+=m*(m+1)/2;
                m=0;
            }
        }
        System.out.print(sum);
    }
}


import java.util.HashMap;
import java.util.Scanner;

public class YetAnotherBrokenKeyboard {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		String str=s.next();
		HashMap<Character,Integer> map=new HashMap<>();

		for(int i=0;i<k;i++) {
			char temp=s.next().charAt(0);
			map.put(temp, 1);
		}
		long sum=0;
		int temp=-1;
		for(int i=0;i<n;i++) {
			if(!map.containsKey(str.charAt(i))) {
				sum=sum+((long)((long)((long)(i-temp-1)*(long)(i-temp)))/2);
				temp=i;
			}
		}

		sum=sum+((long)((long)((long)(str.length()-temp)*(long)(str.length()-1-temp)))/2);
		if(n==0) {
			System.out.println("0");
		}else
		System.out.println(sum);

	}

}


import java.util.HashMap;
import java.util.Scanner;

public class YetAnotherBrokenKeyboard {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		String str=s.next();
		HashMap<Character,Integer> map=new HashMap<>();

		for(int i=0;i<k;i++) {
			char temp=s.next().charAt(0);
			map.put(temp, 1);
		}
		long sum=0;
		int temp=-1;
		for(int i=0;i<n;i++) {
			if(!map.containsKey(str.charAt(i))) {
				sum=sum+((long)((long)((long)(i-temp-1)*(long)(i-temp)))/2);
				temp=i;
			}
		}

		sum=sum+((long)((long)((str.length()-temp)*(str.length()-1-temp)))/2);
		if(n==0) {
			System.out.println("0");
		}else
		System.out.println(sum);

	}

}


import java.util.HashMap;
import java.util.Scanner;

public class YetAnotherBrokenKeyboard {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		String str=s.next();
		HashMap<Character,Integer> map=new HashMap<>();

		for(int i=0;i<k;i++) {
			char temp=s.next().charAt(0);
			map.put(temp, 1);
		}
		long sum=0;
		int temp=-1;
		for(int i=0;i<n;i++) {
			if(!map.containsKey(str.charAt(i))) {
				sum=sum+((long)((long)((i-temp-1)*(i-temp)))/2);
				temp=i;
			}
		}

		sum=sum+((long)((long)((str.length()-temp)*(str.length()-1-temp)))/2);
		if(n==0) {
			System.out.println("0");
		}else
		System.out.println(sum);

	}

}


import java.util.HashMap;
import java.util.Scanner;

public class YetAnotherBrokenKeyboard {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		String str=s.next();
		HashMap<Character,Integer> map=new HashMap<>();

		for(int i=0;i<k;i++) {
			char temp=s.next().charAt(0);
			map.put(temp, 1);
		}
		long sum=0;
		int temp=-1;
		for(int i=0;i<n;i++) {
			if(!map.containsKey(str.charAt(i))) {
				sum=sum+((i-temp-1)*(i-temp))/2;
				temp=i;
			}
		}

		sum=sum+((str.length()-temp)*(str.length()-1-temp))/2;
		if(n==0) {
			System.out.println("0");
		}else
		System.out.println(sum);

	}

}


import java.util.HashMap;
import java.util.Scanner;

public class YetAnotherBrokenKeyboard {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int k=s.nextInt();
		String str=s.next();
		HashMap<Character,Integer> map=new HashMap<>();

		for(int i=0;i<k;i++) {
			char temp=s.next().charAt(0);
			map.put(temp, 1);
		}
		long sum=0;
		int temp=-1;
		for(int i=0;i<n;i++) {
			if(!map.containsKey(str.charAt(i))) {
				sum=sum+(long)((i-temp-1)*(i-temp))/2;
				temp=i;
			}
		}

		sum=sum+(long)((str.length()-temp)*(str.length()-1-temp))/2;
		if(n==0) {
			System.out.println("0");
		}else
		System.out.println(sum);

	}

}


//package cf605;

import java.io.*;
import java.util.*;

public class brokenKeyboard {
    static BufferedReader in;

    public static void solve() throws IOException {
        Integer[] nk = nextArray(2);

        char[] str = in.readLine().toCharArray();

        String[] keys = in.readLine().split(" ");

        Integer[] arr = new Integer[str.length];
        for(int i = 0;i<str.length;i++){
            boolean found = false;
            for(String key : keys){
                char c = key.charAt(0);
                if(str[i] == c){
                    arr[i] = 1;
                    found = true;
                    break;
                }
            }
            if(!found)arr[i] = 0;
        }

//        System.out.println(Arrays.toString(arr));

        int res = 0;
        int start = 0, end = 0;
        while(end < arr.length && start < arr.length){
            if(arr[start] == 1){
                end = start;
                while(end < str.length && arr[end] != 0){
                    end++;
                }
//                System.out.println("start = "+start+" end="+ end);

                res += ((end-start)*(end-start+1))/2;
                start = end;
            }
            else{
                start++;
            }
        }

        System.out.println(res);

    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        solve();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(in.readLine().trim());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(in.readLine().trim());
    }

    static Integer[] nextArray(int n) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        Integer[] tmp = new Integer[n];
        for (int i = 0; i < tmp.length; i++) {
            tmp[i] = Integer.parseInt(st.nextToken());
        }

        return tmp;
    }

}


//package cf605;

import java.io.*;
import java.util.*;

public class brokenKeyboard {
    static BufferedReader in;

    public static void solve() throws IOException {
        Integer[] nk = nextArray(2);

        char[] str = in.readLine().toCharArray();

        String[] keys = in.readLine().split(" ");

        Integer[] arr = new Integer[str.length];
        for(int i = 0;i<str.length;i++){
            boolean found = false;
            for(String key : keys){
                char c = key.charAt(0);
                if(str[i] == c){
                    arr[i] = 1;
                    found = true;
                    break;
                }
            }
            if(!found)arr[i] = 0;
        }

//        System.out.println(Arrays.toString(arr));

        long res = 0;
        int start = 0, end = 0;
        while(end < arr.length && start < arr.length){
            if(arr[start] == 1){
                end = start;
                while(end < str.length && arr[end] != 0){
                    end++;
                }
//                System.out.println("start = "+start+" end="+ end);
                long tmp = ((end-start)*(end-start+1))/2;
                res += tmp;
                start = end;
            }
            else{
                start++;
            }
        }

        System.out.println(res);

    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        solve();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(in.readLine().trim());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(in.readLine().trim());
    }

    static Integer[] nextArray(int n) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        Integer[] tmp = new Integer[n];
        for (int i = 0; i < tmp.length; i++) {
            tmp[i] = Integer.parseInt(st.nextToken());
        }

        return tmp;
    }

}


//package cf605;

import java.io.*;
import java.util.*;

public class brokenKeyboard {
    static BufferedReader in;

    public static void solve() throws IOException {
        Integer[] nk = nextArray(2);

        char[] str = in.readLine().toCharArray();

        String[] keys = in.readLine().split(" ");

        Integer[] arr = new Integer[str.length];
        for(int i = 0;i<str.length;i++){
            boolean found = false;
            for(String key : keys){
                char c = key.charAt(0);
                if(str[i] == c){
                    arr[i] = 1;
                    found = true;
                    break;
                }
            }
            if(!found)arr[i] = 0;
        }

//        System.out.println(Arrays.toString(arr));

        long res = 0;
        int start = 0, end = 0;
        while(end < arr.length && start < arr.length){
            if(arr[start] == 1){
                end = start;
                while(end < str.length && arr[end] != 0){
                    end++;
                }
//                System.out.println("start = "+start+" end="+ end);

                res += ((end-start)*(end-start+1))/2;
                start = end;
            }
            else{
                start++;
            }
        }

        System.out.println(res);

    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        solve();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(in.readLine().trim());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(in.readLine().trim());
    }

    static Integer[] nextArray(int n) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        Integer[] tmp = new Integer[n];
        for (int i = 0; i < tmp.length; i++) {
            tmp[i] = Integer.parseInt(st.nextToken());
        }

        return tmp;
    }

}


package cf605;

import java.io.*;
import java.util.*;

public class brokenKeyboard {
    static BufferedReader in;

    public static void solve() throws IOException {
        Integer[] nk = nextArray(2);

        char[] str = in.readLine().toCharArray();

        String[] keys = in.readLine().split(" ");

        Integer[] arr = new Integer[str.length];
        for(int i = 0;i<str.length;i++){
            boolean found = false;
            for(String key : keys){
                char c = key.charAt(0);
                if(str[i] == c){
                    arr[i] = 1;
                    found = true;
                    break;
                }
            }
            if(!found)arr[i] = 0;
        }

//        System.out.println(Arrays.toString(arr));

        int res = 0;
        int start = 0, end = 0;
        while(end < arr.length && start < arr.length){
            if(arr[start] == 1){
                end = start;
                while(end < str.length && arr[end] != 0){
                    end++;
                }
//                System.out.println("start = "+start+" end="+ end);

                res += ((end-start)*(end-start+1))/2;
                start = end;
            }
            else{
                start++;
            }
        }

        System.out.println(res);

    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        solve();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(in.readLine().trim());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(in.readLine().trim());
    }

    static Integer[] nextArray(int n) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        Integer[] tmp = new Integer[n];
        for (int i = 0; i < tmp.length; i++) {
            tmp[i] = Integer.parseInt(st.nextToken());
        }

        return tmp;
    }

}


//package cf605;

import java.io.*;
import java.util.*;

public class brokenKeyboard {
    static BufferedReader in;

    public static void solve() throws IOException {
        Integer[] nk = nextArray(2);

        char[] str = in.readLine().toCharArray();

        String[] keys = in.readLine().split(" ");

        Integer[] arr = new Integer[str.length];
        for(int i = 0;i<str.length;i++){
            boolean found = false;
            for(String key : keys){
                char c = key.charAt(0);
                if(str[i] == c){
                    arr[i] = 1;
                    found = true;
                    break;
                }
            }
            if(!found)arr[i] = 0;
        }

//        System.out.println(Arrays.toString(arr));

        long res = 0;
        int start = 0, end = 0;
        while(end < arr.length && start < arr.length){
            if(arr[start] == 1){
                end = start;
                while(end < str.length && arr[end] != 0){
                    end++;
                }
//                System.out.println("start = "+start+" end="+ end);
                long tmp = ((long)(end-start)*(long)(end-start+1))/2;
                res += tmp;
                start = end;
            }
            else{
                start++;
            }
        }

        System.out.println(res);

    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        solve();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(in.readLine().trim());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(in.readLine().trim());
    }

    static Integer[] nextArray(int n) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        Integer[] tmp = new Integer[n];
        for (int i = 0; i < tmp.length; i++) {
            tmp[i] = Integer.parseInt(st.nextToken());
        }

        return tmp;
    }

}


//package cf605;

import java.io.*;
import java.util.*;

public class brokenKeyboard {
    static BufferedReader in;

    public static void solve() throws IOException {
        Integer[] nk = nextArray(2);

        char[] str = in.readLine().toCharArray();

        String[] keys = in.readLine().split(" ");

        Integer[] arr = new Integer[str.length];
        for(int i = 0;i<str.length;i++){
            boolean found = false;
            for(String key : keys){
                char c = key.charAt(0);
                if(str[i] == c){
                    arr[i] = 1;
                    found = true;
                    break;
                }
            }
            if(!found)arr[i] = 0;
        }

//        System.out.println(Arrays.toString(arr));

        int res = 0;
        int start = 0, end = 0;
        while(end < arr.length && start < arr.length){
            if(arr[start] == 1){
                end = start;
                while(end < str.length && arr[end] != 0){
                    end++;
                }

                res += ((end-start)*(1+end-start))/2;
                start = end+1;
            }
            else{
                start++;
            }
        }

        System.out.println(res);

    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        solve();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(in.readLine().trim());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(in.readLine().trim());
    }

    static Integer[] nextArray(int n) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        Integer[] tmp = new Integer[n];
        for (int i = 0; i < tmp.length; i++) {
            tmp[i] = Integer.parseInt(st.nextToken());
        }

        return tmp;
    }

}


// Working program using BufferedReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;
import java.util.stream.Collectors;

public class Codeforces_round605 {

    static int mindistance(int a,int b,int c) {
        int res = 0;
        if(a == b) {
            if (c != a) {
                if(c-1 != a) return 2*(c-a-2);
                else return 0;
            }
            else return 0;

        }
        else if(b == c) {
            if (c != a) {
                if(c-1 != a) return 2*(c-a-2);
                else return 0;
            }
            else return 0;
        }
        else {
            return b-a-1 + c-a-2 + c-1-b;
        }
    }
    static String corr_seq(String s) {
        char[] ss = s.toCharArray();
        HashMap<Character,Integer> counts = new HashMap<Character, Integer>();
        counts.put('L',0);
        counts.put('R',0);
        counts.put('U',0);
        counts.put('D',0);
        for(char c:ss) {
            counts.put(c,counts.get(c)+1);
        }
        int L = Math.min(counts.get('L'),counts.get('R'));
        int U = Math.min(counts.get('U'),counts.get('D'));
        if (L ==0 && U>1)  {
            U = 1;
        }
        if (U ==0 && L>1)  {
            L = 1;
        }
        StringBuffer res = new StringBuffer();
        for(int i =0; i < U; i++) {
            res.append("U");
        }
        for(int i =0; i < L; i++) {
            res.append("L");
        }
        for(int i =0; i < U; i++) {
            res.append("D");
        }
        for(int i =0; i < L; i++) {
            res.append("R");
        }
        return res.toString();
    }
    static int numofsubstrings(String s, HashSet<Character> allowed,int n,int k) {
        int i=0,j=0;
        int res = 0;
        char[] ss = s.toCharArray();
        while (i <n) {
            j = i;
            while( j < n && allowed.contains(ss[j])) {
                j++;
            }
            res += (j-i)*(j-i+1)/2;
            i = j+1;
        }
        return res;

    }
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));

        String[] frisltine = br.readLine().split(" ");
        int n = Integer.parseInt(frisltine[0]);
        int k = Integer.parseInt(frisltine[1]);

            String s = br.readLine();
        HashSet<Character> allowed = new HashSet<Character>();
        String[] all = br.readLine().split(" ");
        for (String ss: all) {
            char c =  ss.charAt(0);
            allowed.add(c);
        }
            int res = numofsubstrings(s,allowed,n,k);
           System.out.println(res);

    }

}


// Working program using BufferedReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.*;
import java.util.stream.Collectors;

public class Codeforces_round605 {

    static int mindistance(int a,int b,int c) {
        int res = 0;
        if(a == b) {
            if (c != a) {
                if(c-1 != a) return 2*(c-a-2);
                else return 0;
            }
            else return 0;

        }
        else if(b == c) {
            if (c != a) {
                if(c-1 != a) return 2*(c-a-2);
                else return 0;
            }
            else return 0;
        }
        else {
            return b-a-1 + c-a-2 + c-1-b;
        }
    }
    static String corr_seq(String s) {
        char[] ss = s.toCharArray();
        HashMap<Character,Integer> counts = new HashMap<Character, Integer>();
        counts.put('L',0);
        counts.put('R',0);
        counts.put('U',0);
        counts.put('D',0);
        for(char c:ss) {
            counts.put(c,counts.get(c)+1);
        }
        int L = Math.min(counts.get('L'),counts.get('R'));
        int U = Math.min(counts.get('U'),counts.get('D'));
        if (L ==0 && U>1)  {
            U = 1;
        }
        if (U ==0 && L>1)  {
            L = 1;
        }
        StringBuffer res = new StringBuffer();
        for(int i =0; i < U; i++) {
            res.append("U");
        }
        for(int i =0; i < L; i++) {
            res.append("L");
        }
        for(int i =0; i < U; i++) {
            res.append("D");
        }
        for(int i =0; i < L; i++) {
            res.append("R");
        }
        return res.toString();
    }
    static int numofsubstrings(String s, HashSet<Character> allowed,int n,int k) {
        int i=0,j=0;
        int res = 0;
        char[] ss = s.toCharArray();
        while (i <n) {
            j = i;
            while( j < n && allowed.contains(ss[j])) {
                j++;
            }
            res += (j-i)*(j-i+1)/2;
            i = j+1;
        }
        return res;

    }
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));

        String[] frisltine = br.readLine().split(" ");
        int n = Integer.parseInt(frisltine[0]);
        int k = Integer.parseInt(frisltine[1]);

            String s = br.readLine();
        HashSet<Character> allowed = new HashSet<Character>();
        String[] all = br.readLine().split(" ");
        for (String ss: all) {
            if (ss.length() > 0) {
            char c =  ss.charAt(0);
            allowed.add(c); }
        }
            int res = numofsubstrings(s,allowed,n,k);
           System.out.println(res);

    }

}