#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; int main() { int T; cin>>T; FOR(t,0,T) { int N; cin>>N; vector L(N); map M; FOR(i,0,N) { cin>>L[i]; M[L[i]]++; } int ans = 0; priority_queue Q; for(auto x : M) Q.push(x.second); while(!Q.empty()) { int a = Q.top();Q.pop(); if(Q.empty()) break; int b = Q.top();Q.pop(); if(Q.empty()) break; int c = Q.top();Q.pop(); ans += c; a -= c; b-= c; c = 0; if(a > 0) Q.push(a); if(b > 0) Q.push(b); } while(!Q.empty()) Q.pop(); cout << ans << endl; } }