#include #define For(i, a, b) for(int i = a; i < b; i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(int i = a; i >= b; i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using namespace std; using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; int main() { int t; cin >> t; while (t--) { int n; cin >> n; map mp; rep(_, n) { int l; cin >> l; mp[l]++; } multiset> s; for (auto [fi, se] : mp) { s.insert({se, fi}); } int ans = 0; while (s.size() >= 3) { auto it = s.end(); it--; auto [a, ia] = *it; it--; auto [b, ib] = *it; it--; auto [c, ic] = *it; ans++; s.erase(s.find({a, ia})); mp[ia]--; if (mp[ia] > 0) { s.insert({mp[ia], ia}); } s.erase(s.find({b, ib})); mp[ib]--; if (mp[ib] > 0) { s.insert({mp[ib], ib}); } s.erase(s.find({c, ic})); mp[ic]--; if (mp[ic] > 0) { s.insert({mp[ic], ic}); } } cout << ans << endl; } }