import bisect from collections import Counter def max_kadomatsu_groups(test_cases): results = [] for case in test_cases: N, L = case if N < 3: results.append(0) continue freq = list(Counter(L).values()) max_possible = N // 3 low, high = 0, max_possible best = 0 while low <= high: mid = (low + high) // 2 total = sum(min(f, mid) for f in freq) if total >= 3 * mid: best = mid low = mid + 1 else: high = mid - 1 results.append(best) return results # Read input and process import sys def main(): input = sys.stdin.read().split() ptr = 0 T = int(input[ptr]) ptr += 1 test_cases = [] for _ in range(T): N = int(input[ptr]) ptr += 1 L = list(map(int, input[ptr:ptr + N])) ptr += N test_cases.append((N, L)) results = max_kadomatsu_groups(test_cases) for res in results: print(res) if __name__ == '__main__': main()