T = gets.to_i N, L = (1..T).map {[gets.to_i, gets.split.map(&:to_i)]}.transpose def f(a) if a.size <= 2 or a[2] == 0 0 else 1 + f(a.map.with_index {|x, i| if i <= 2 x - 1 else x end }.sort.reverse) end end ans = L.map {|l| f(l.inject(Hash.new(0)) {|hash, x| hash[x] += 1; hash}.values.sort.reverse) } puts ans