#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; 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.size()>=3) { int a = Q.top();Q.pop(); int b = Q.top();Q.pop(); int c = Q.top();Q.pop(); ans += c; if(c <= 0) break; Q.push(a-c); Q.push(b-c); } printf("%d\n", ans); } }