import std.algorithm, std.array, std.container, std.range; import std.string, std.conv; import std.math, std.bigint, std.bitmanip, std.random; import std.stdio, std.typecons; const auto mod = 10 ^^ 9 + 7; void main() { auto t = readln.chomp.to!int; foreach (_; 0..t) { auto n = readln.chomp.to!int; auto ai = readln.split.map!(to!int).array; ai.sort!("a > b"); auto gi = ai.group.map!("a[1]").map!(to!int).array; writeln(calc(gi, 0)); } } int calc(int[] gi, int acc) { if (gi.length < 3) { return acc; } else { gi[0..3] -= 1; gi.sort!("a > b"); return calc(gi.until(0).array, acc + 1); } }