import sys from collections import Counter def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def solve(): T = int(input()) for i in range(T): N = int(input()) Ls = [int(i) for i in input().split()] cnt = Counter(Ls) ans = 0 while len(cnt) >= 3: ans += 1 kdmt = [key for key, value in cnt.most_common(3)] for i in kdmt: cnt[i] -= 1 if cnt[i] == 0: del cnt[i] print(ans) if __name__ == '__main__': solve()