T = int(input()) for case in range(T): N = int(input()) L = list(map(int, input().split())) rem = [] app = set() for i in range(N): if L[i] not in app: app.add(L[i]) rem.append(L.count(L[i])) rem.sort(reverse = True) if len(rem) < 3: print(0) continue ans = 0 while True: if rem[2] <= 0: break ans += 1 rem[0] -= 1 rem[1] -= 1 rem[2] -= 1 rem.sort(reverse = True) print(ans)