#include <bits/stdc++.h>
#include <sstream>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
vector<ll>m;
ll sum=0;

ll fast(ll x,ll y)
{
    ll r=1;

    while(y>0)
    {
        if(y%2==1)
            r=r*x;
        x=x*x;
        y=y/2;
    }
    return r;
}

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

   //freopen("rock.in","r",stdin);

    int t;
    cin>>t;

    int n;
    while(t--)
    {
        cin>>n;
        int *x;
        x=new int[n];

        for(int i=0;i<n;i++)
            cin>>x[i];

        int h=n-1;

        sort(x,x+n);

        for(int i=0;i<n-1;i++)
        {
            if(x[i+1]>x[i])
            {
                break;
            }
            else
                h--;
        }

        cout<<h<<endl;


    }

return 0;
}
