#include #include #include #include using namespace std; int main(){ int t; cin >> t; while(t-- > 0){ int n, x; cin >> n; map cnt; for(int i = 0; i < n; i++){ cin >> x; cnt[x]++; } vector counts; for(map::iterator it = cnt.begin(); it != cnt.end(); it++){ counts.push_back((*it).second); } sort(counts.begin(), counts.end()); int ans = 0; while(counts.size() >= 3){ int len = counts.size(); if(counts[len-3] == 0) break; ans += counts[len-3]; counts[len-1] -= counts[len-3]; counts[len-2] -= counts[len-3]; counts[len-3] -= counts[len-3]; sort(counts.begin(), counts.end()); } cout << ans << endl; } return 0; }