#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int t; cin >> t;
while(t--){
int n,x; cin >> n;
unordered_map<int,int> f;
for(int i=0;i<n;i++){
cin >> x;
f[x]++;
}
int mx = 0;
for(auto it = f.begin();it != f.end();++it){
mx = max(mx,it->second);
}
cout << n-mx << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCB0OwljaW4gPj4gdDsKCXdoaWxlKHQtLSl7CgkJaW50IG4seDsJY2luID4+IG47CgkJdW5vcmRlcmVkX21hcDxpbnQsaW50PiBmOwoJCWZvcihpbnQgaT0wO2k8bjtpKyspewoJCQljaW4gPj4geDsKCQkJZlt4XSsrOwoJCX0JCgkJaW50IG14ID0gMDsKCQlmb3IoYXV0byBpdCA9IGYuYmVnaW4oKTtpdCAhPSBmLmVuZCgpOysraXQpewoJCQlteCA9IG1heChteCxpdC0+c2Vjb25kKTsKCQl9CgkJY291dCA8PCBuLW14IDw8IGVuZGw7Cgl9CglyZXR1cm4gMDsKfQ==