from collections import Counter from heapq import heapify, heappop, heappush t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) hq = [(-c[1], c[1]) for c in Counter(l).most_common()] heapify(hq) count = 0 while len(hq) >= 3: ls = [] for i in range(3): ls.append(heappop(hq)[1]) for i in range(3): if ls[i] > 1: ls[i] -= 1 heappush(hq, (-ls[i], ls[i])) count += 1 print(count)