from collections import Counter T = int(input()) for _ in range(T): N = int(input()) L = list(map(int, input().split())) cnt = Counter(L) count = 0 while True: m = cnt.most_common(3) if len(m) == 3: if m[2][1] != 0: count += m[2][1] sub = Counter({i[0]:m[2][1] for i in m}) cnt.subtract(sub) else: break else: break print(count)