from collections import Counter T = input() for i in xrange(T): N = input() l = Counter(map(int,raw_input().split())).values() ans = 0 if len(l) < 3: print ans continue l.sort() while l[-3] > 0: ans += l[-3] l[-1] -= l[-3] l[-2] -= l[-3] l[-3] = 0 l.sort() print ans