use std::io::*; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let t: usize = itr.next().unwrap().parse().unwrap(); let mut out = Vec::new(); for _ in 0..t { let n: usize = itr.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let mut map = std::collections::HashMap::new(); for i in 0..n { let p = map.entry(a[i]).or_insert(0); *p += 1; } let mut l = 0; let mut r = 1 << 30; while r - l > 1 { let mid = (l + r) >> 1; if map.iter().fold(0, |acc, x| acc + std::cmp::min(mid, *x.1)) >= mid * 3 { l = mid; } else { r = mid; } } writeln!(out, "{}", l).ok(); } stdout().write_all(&out).unwrap(); }