z=[0]
s=r=0..9
gets.to_i.times{m=r.map{gets.split.map(&:to_i)+z}+[z*11]
puts ([[0,1].product(*[[0,1]]*9).find{|a|s=m.dup<<a+z
r.map{|i|s[i]=s[i][r].zip(e=s[i-1],s[i-2],e.rotate,e.rotate(-1)).map{|l|l.inject(:+)%2}+z}
s[9].all?{|j|j==0}}]+s[0,9]).map{|a|a[r]*" "}}