from collections import Counter import heapq t = int(input()) for i in range(t): n = int(input()) L = Counter(map(int, input().split())) kosu = [-x for x in L.values()] heapq.heapify(kosu) ans = 0 while len(kosu) > 2: a = heapq.heappop(kosu) b = heapq.heappop(kosu) c = heapq.heappop(kosu) ans += 1 a += 1 b += 1 c += 1 if a < 0: heapq.heappush(kosu, a) if b < 0: heapq.heappush(kosu, b) if c < 0: heapq.heappush(kosu, c) print(ans)