from collections import Counter import heapq def solve(N, L): c2 = Counter(Counter(L).values()) h = [0, 0, 0] for n in sorted(c2.keys(), reverse=True): k = c2[n] for i in range(k): heapq.heappush(h, -n) c = 0 while h: n1 = heapq.heappop(h) n2 = heapq.heappop(h) n3 = heapq.heappop(h) if n3 == 0: break c += 1 heapq.heappush(h, n1 + 1) heapq.heappush(h, n2 + 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()