from collections import * from heapq import * import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MF(): return map(float, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LF(): return list(map(float, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def main(): t=II() for _ in range(t): n=II() ll=LI() ll=Counter(ll) ll=[-x for x in ll.values()] heapify(ll) ans=0 while len(ll)>2: l1=-heappop(ll) l2=-heappop(ll) l3=-heappop(ll) #print(l1,l2,l3,ll) l1-=1 l2-=1 l3-=1 ans+=1 if l1:heappush(ll,-l1) if l2:heappush(ll,-l2) if l3:heappush(ll,-l3) print(ans) main()