sub q{$;=1;for(0..3){$;[$_]=int(rand(9))}}sub _{print@_}&q;for(;;){$:=$~=0 ;_"$/$; ";$_=<>;if(/^\d{4}$/){@q=split//;--$#q;$@=-1;for(@q){$a=$_;($a==$; [++$@])&&++$:||(grep/$a/,@;)&&++$~}_"$~W$:B ";++$;;$:==4|$;>10&&_(@;)&&&q}}