from collections import Counter import heapq t=int(input()) for tests in range(t): N=int(input()) A=list(map(int,input().split())) C=Counter(A) H=list(C.values()) H=[-h for h in H] heapq.heapify(H) ANS=0 while len(H)>=3: x=heapq.heappop(H) y=heapq.heappop(H) z=heapq.heappop(H) x+=1 y+=1 z+=1 ANS+=1 if x!=0: heapq.heappush(H,x) if y!=0: heapq.heappush(H,y) if z!=0: heapq.heappush(H,z) print(ANS)