from collections import defaultdict def check(x): n = N for v in dic.values(): if v > x: n -= v - x return n >= 3 * x for _ in range(int(input())): N = int(input()) L = list(map(int, input().split())) dic = defaultdict(int) for l in L: dic[l] += 1 lb = 0 ub = N // 3 + 1 while ub - lb > 1: mid = (ub + lb) // 2 if check(mid): lb = mid else: ub = mid print(lb)