$r=0..8
def f
a=yield$m
b=yield$c
$r.map{|i|l=a[i];(?1..?9).map{|d|(l-[d]).size<8&&$r.map{|j|l[j]==d&&b[i][j]=?*}}}
$m=yield a
$c=yield b
end
puts ("1\n"..gets).map{$c=$r.map{[" "]*9};$m=$r.map{|i|gets.chop.split}
f{|a|a}
f &:transpose
f{|a|a.map{|l|l.each_slice 3}.each_slice(3).flat_map{|i,*j|i.zip(*j).map &:flatten}}
$r.map{|i|$c[i].zip($m[i])<<?\n}*""}*?\n