from collections import defaultdict from heapq import heappop,heappush def solve(): N = int(input()) L = list(map(int,input().split())) dic = defaultdict(int) for i in range(N): dic[L[i]] += 1 hq = [] for v in dic.values(): heappush(hq, -v) ans = 0 while len(hq) >= 3: ans += 1 v = [] for _ in range(3): v.append(heappop(hq)) for i in range(3): if v[i] + 1 == 0: continue heappush(hq, v[i]+1) print(ans) T = int(input()) for _ in range(T): solve()