import collections import heapq def solve(N, L): c = collections.Counter() for Li in L: c[Li] -= 1 if len(c) < 3: return 0 res = 0 cnt = list(c.values()) heapq.heapify(cnt) mx = [0] * 3 while True: kadomatsu = True for i in range(len(mx)): mx[i] = heapq.heappop(cnt) if mx[i] >= 0: kadomatsu = False if kadomatsu: res += 1 else: break for i in range(len(mx)): heapq.heappush(cnt, mx[i] + 1) return res T = int(input()) lis = [0] * T for tt in range(T): nt = int(input()) lt = [int(x) for x in input().split()] lis[tt] = solve(nt, lt) print(*lis, sep='\n')