import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int j = 0; j < t; j++) { int n = sc.nextInt(); HashMap map = new HashMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (map.containsKey(x)) { map.put(x, map.get(x) + 1); } else { map.put(x, 1); } } int[] counts = new int[n + 1]; for (int x : map.values()) { counts[x]++; } int left = 0; int right = n / 3 + 1; while (right - left > 1) { int m = (left + right) / 2; if (check(m, counts)) { left = m; } else { right = m; } } sb.append(left).append("\n"); } System.out.print(sb); } static boolean check(int target, int[] counts) { int count = 0; for (int i = 1; i < counts.length; i++) { count += Math.min(target, i) * counts[i]; if (count >= target * 3) { return true; } } return false; } }