import std.stdio; import std.array; import std.string; import std.algorithm; import std.math; import std.range; import std.conv; import std.typecons; // solve ============= T solve(T)(T[] xs, T acc = 0){ xs.sort.reverse; if( xs[2] == 0 ){ return acc; } else { --xs[0..3]; } return solve(xs, ++acc); } // main =============== void main(){ readln; foreach(line; stdin.byLine){ if(line.empty) break; auto ls = readln.chomp.split(" ").map!(to!int).array.sort; auto groupLs = ls.group.map!("a[1]").array; //uint writeln( groupLs.length >= 3 ? solve(groupLs) : 0 ); } }