#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define vi vector<int>
#define vc vector<char>
#define vd vector<double>
#define vpi vector<pair<int,int> >
#define vvi vector<vector<int> >
#define si set<int>
#define mi map<int,int>
#define all(v) v.begin(),v.end()
// son
#define fo(i,a,b) ;for(int i=a; i<b; i++)
#define fd(i,a,b) ;for(int i=a; i>=b; i--)
#define MOD 1000000007
#define top(a,b,c,d) ((a==b)?c:d);
#define MI INT_MIN
#define MA INT_MAX
#define PI 3.14159265358979323846
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define MAXN 100005

//template<typename T>             vector<T>& operator--            (vector<T> &v){for (auto& i : v) --i;            return  v;}
//template<typename T>             vector<T>& operator++            (vector<T> &v){for (auto& i : v) ++i;            return  v;}
template<typename T>             istream& operator>>(istream& is,  vector<T> &v){for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>  v){for (auto& i : v) os << i << ' '; return os;}
/*template<typename T, typename U> pair<T,U>& operator--           (pair<T, U> &p){--p.first; --p.second;            return  p;}
template<typename T, typename U> pair<T,U>& operator++           (pair<T, U> &p){++p.first; ++p.second;            return  p;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>  p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}*/

//ASCII
//'0' - 48
//'9' - 57
//'a' - 97
//'A' - 65

void test_case(int test) {
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    sort(a.begin(), a.end());
    // cout << "size "<< a.size() << "\n" ;
    int k=n;
    int ctr=0;
    fd(i,n-1,1){
        if(a[i]==a[i-1]){
           continue;
        }
        else{
            ctr += k-i;
            k=i;
            //cout << "ctr: " << ctr << "k: " << k << "\n";
        }
    }
    cout << ctr << "\n";

}

int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int T;
    cin >> T;
    for (int test = 1; test <= T; ++test) {
        test_case(test);
    }

    return 0;
}



