import heapq T = int(input()) for _ in range(T): N = int(input()) L = sorted(list(map(int,input().split()))) C = {} for i in range(N): C[L[i]] = C.get(L[i],0)+1 C = list(C.items()) C = sorted([(-c,l) for l,c in C]) que = [] for c,x in C: heapq.heappush(que,(c,x)) ans = 0 while len(que)>=3: c1,x1 = heapq.heappop(que) c2,x2 = heapq.heappop(que) c3,x3 = heapq.heappop(que) ans += 1 c1 += 1 c2 += 1 c3 += 1 if c1<0: heapq.heappush(que,(c1,x1)) if c2<0: heapq.heappush(que,(c2,x2)) if c3<0: heapq.heappush(que,(c3,x3)) print(ans)