($W,$H,$X)=glob<>; for$i(0..$H%3/2){ for$j(0..$W%3/2){ $X-=$_[$i+!($H%3)][$j+!($W%3)]=$X<9?$X:9 } } print$X?-1 .$/:map{(map$_[$'%3][$_%3]+0,0..$W-//),$/}0..$H-1