#yuki_120 from collections import Counter n=int(raw_input()) for i in xrange(n): int(raw_input()) s=Counter(map(int,raw_input().split())).values() # print s res=0 if len(s)>=3: s=sorted(s,reverse=True) while s[2]: s[0]-=1 s[1]-=1 s[2]-=1 res+=1 s=sorted(s,reverse=True) print res