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