from collections import Counter import heapq def solve(N, L): c2 = Counter(Counter(L).values()) h = [] for n in sorted(c2.keys(), reverse=True): k = c2[n] for i in range(k): heapq.heappush(h, -n) c = 0 while len(h) >= 3: c += 1 n1 = heapq.heappop(h) n2 = heapq.heappop(h) n3 = heapq.heappop(h) if n1 < -1: heapq.heappush(h, n1 + 1) if n2 < -1: heapq.heappush(h, n2 + 1) if n3 < -1: heapq.heappush(h, n3 + 1) return c def main(): T = int(input()) for t in range(T): N = int(input()) L = list(map(int, input().split())) print(solve(N, L)) if __name__ == '__main__': main()