($h,$w,$n)=glob<>; for$y(1..$h){ $_=<>; for$x(0..$w-1){ if(substr($_,$x,1)eq'#'){ ++$a[$x]; } } } for$t(0..$n-1){ $c=<>; $t[$c]=$t; $e[$c+0]+=3; $e[$c+1]+=3; $e[$c+2]+=3; push@b,sprintf"%6d,%6d",$c,$t; } @b=sort@b; for$j(0..$#b){ $_=$b[$j]; /,/,$c=$`,$t=$'; $j[$t]=$j; $e[$c+0]-=3; $a[$c+0]-=$r[$j][0]=$-=$a[$c+0]-$e[$c+0]; $e[$c+1]-=3; $a[$c+1]-=$r[$j][1]=$-=$a[$c+1]-$e[$c+1]; $e[$c+2]-=3; $a[$c+2]-=$r[$j][2]=$-=$a[$c+2]-$e[$c+2]; if($r[$j][0]+$r[$j][1]+$r[$j][2]==0){ if($a[$c+0]){ $r[$j][0]=1; --$a[$c+0]; }elsif($a[$c+1]){ $r[$j][1]=1; --$a[$c+1]; }elsif($a[$c+2]){ $r[$j][2]=1; --$a[$c+2]; }else{ last; #die; } } } for$t(0..$n-1){ $j=$j[$t]; print $r[$j][0]>0?'#':'.'; print $r[$j][1]>0?'#':'.'; print $r[$j][2]>0?'#':'.'; print "\n"; print $r[$j][0]>1?'#':'.'; print $r[$j][1]>1?'#':'.'; print $r[$j][2]>1?'#':'.'; print "\n"; print $r[$j][0]>2?'#':'.'; print $r[$j][1]>2?'#':'.'; print $r[$j][2]>2?'#':'.'; print "\n"; }