from collections import defaultdict for _ in range(int(input())): N = int(input()) L = list(map(int,input().split())) dic = defaultdict(int) for l in L: dic[l] += 1 cnt = 0 N3 = N //3 for v in dic.values(): if v > N3: cnt += v - N3 print((N - cnt)//3)