import heapq import collections def solve(N, Ls): counts = collections.Counter(Ls) vals = [-c for c in counts.values()] heapq.heapify(vals) while N: c = -vals[0] if c <= N // 3: return N // 3 newc = (N - c) // 2 N -= c - newc heapq.heapreplace(vals, -newc) return 0 T = int(input()) for t in range(T): N = int(input()) Ls = list(map(int, input().split())) print(solve(N, Ls))