#include using namespace std; typedef long long ll; int main() { int t;cin>>t; while (t--) { int n;cin>>n; map mp; for (int i=0;i>a; mp[a]++; } int m=mp.size(); vector v; for (auto p:mp) v.push_back(p.second); sort(v.rbegin(), v.rend()); int ans=0; if (v.size() >= 3) { while (v[2]) { ans+=v[0]; v[2]-=v[0]; v[1]-=v[0]; v[0]=0; sort(v.rbegin(),v.rend()); } } cout<