#include #include #include #include #include using namespace std; int main(){ int T,N,L; for(scanf("%d",&T);T--;){ mapm; for(scanf("%d",&N);N--;m[L]++)scanf("%d",&L); priority_queue >q; for(map::iterator it=m.begin();it!=m.end();++it)q.push(make_pair(it->second,it->first)); int r=0,mi; for(;q.size()>2;r+=mi){ mi=INT_MAX; vector >v(3); for(int i=0;i<3;i++)v[i]=q.top(),mi=min(mi,v[i].first),q.pop(); for(int i=0;i<3;i++)if(v[i].first>mi)q.push(make_pair(v[i].first-mi,v[i].second)); } printf("%d\n",r); } }