from collections import Counter from heapq import heapify, heappop, heappush for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) counter = Counter(A) H = [-cnt for cnt in counter.values()] heapify(H) ans = 0 while len(H) >= 3: a = -heappop(H) b = -heappop(H) c = -heappop(H) ans += 1 if a > 1: heappush(H, -a + 1) if b > 1: heappush(H, -b + 1) if c > 1: heappush(H, -c + 1) print(ans)