# -*- coding:utf-8 -*- import collections def solve(): n = input() L = map(int,raw_input().split()) cnt = collections.Counter(L) if len(set(L)) < 3: print 0 return no1 = cnt.most_common(1)[0][1] if no1 <= n /3: print n / 3 else: no2 = cnt.most_common(2)[1][1] if no2 > n - no1: print n - no1 - no2 else: print (n-no1) / 2 if __name__ == "__main__": t = input() for i in xrange(t): solve()