#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; while(t--) { int N; cin>>N; int L[N]; FOR(i,0,N) cin>>L[i]; sort(L, L + N); map M; FOR(i,0,N) 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; } return 0; }