#include <bits/stdc++.h>
using namespace std;

#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define mod 1000000007
#define mod2 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define en "\n"
#define MN INT_MIN
#define MX INT_MAX
#define fr(a,b) for(long long int i=a;i<b;i++)
#define mem(a,b) memset(a,b,sizeof(a));

typedef long long int ll;



int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll T = 1;
	cin >> T;

	while (T--)
	{
		ll n;
		cin >> n;
		ll a[n];
		for (ll i = 0; i < n; i++)
			cin >> a[i];
		sort(a, a + n);
		ll x = 0, p = 0;
		for (ll i = 1; i < n; i++)
		{
			if (a[i] != a[i - 1])
			{	x += 1;}
			else if (a[i] == a[i - 1])
			{	if (x > 0)
					x += 1;
			}
		}
		cout << x << "\n";

	}
	return 0;
}