from collections import Counter from heapq import * def solve(): N = int(input()) L = list(map(int, input().split())) counter = Counter(L) 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) T = int(input()) for _ in range(T): solve()