/**Bismillahir Rahmanir Rarim**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c)              c.begin(), c.end()
#define CC(x) cout << (x) << endl
#define rep(i,n) for(int i=0;i<n;i++)
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define EPS 1e-9
#define sz(v) int((v).size())
#define vi vector<ll>
#define pii pair<ll,ll>
const unsigned long long inf=1e18;
const int range=1e6;
const long long inff=1e-12;
int dx[]= {0,-1, 0,1};
int dy[]= {1, 0,-1,0};
typedef unsigned long long ull;
ll gcd(ll a, ll b) {if (b == 0)return a;return gcd(b, a % b);}
using namespace std;
bool cmp(const pair<ll,ll>&a, const pair<ll,ll>&b){return (a.se>b.se);}
void vecp(vector<ll>v){for(int i=0;i<sz(v);i++){cout <<v[i]<<" ";}cout <<endl;}
int main()
{
    FastRead
    int x,y,a,b,z,t,k,l,r,c,d,x1,x2,f=1;
    cin >> t;
    while(t--){
        cin >>x;
        vi v(x);
        map<int,int>m;
        for(int i=0;i<x;i++){
            cin >>v[i];
            m[v[i]]++;
        }
        int ans=0;
        a=0;
        for(auto i:m){
            if(a==0){
                a++;
                continue;
            }
            else{
                ans+=(i.se);
            }
            a++;
        }
        cout <<ans <<endl;

    }
}
