# -*- coding: utf-8 -*- from collections import Counter T = int(raw_input()) for i in xrange(T): N = int(raw_input()) L = map(int, raw_input().split()) counter = Counter() for l in L: counter[l] += 1 M = [] for cnt in counter: M.append(counter[cnt]) count = 0 while 1: M.sort(reverse=True) if len(M)<3: break if M[0] > 0 and M[1] > 0 and M[2] > 0: M[0] -= 1 M[1] -= 1 M[2] -= 1 count += 1 else: break print count