import heapq def f(): _ = input() D = {} for L in map(int, input().split()): D[L] = D.setdefault(L, 0) + 1 hq = [-v for v in D.values()] heapq.heapify(hq) kl = [None] * 3 ans = 0 while True: if len(hq) < 3: print(ans) return for i in range(3): kl[i] = heapq.heappop(hq) + 1 for i in range(3): if kl[i] != 0: heapq.heappush(hq, kl[i]) ans += 1 return T = int(input()) for _ in range(T): f()