($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; push@b,sprintf"%6d,%6d",$c,$t; } @b=sort@b; for($j=0;$j<@b;++$j){ $_=$b[$j]; /,/,$c=$`,$t=$'; $j[$t]=$j; $r[$j][0]=$a[$c+0]<3?$a[$c+0]:3; $a[$c+0]-=$r[$j][0]; $r[$j][1]=$a[$c+1]<3?$a[$c+1]:3; $a[$c+1]-=$r[$j][1]; $r[$j][2]=$a[$c+2]<3?$a[$c+2]:3; $a[$c+2]-=$r[$j][2]; while($r[$j][0]+$r[$j][1]+$r[$j][2]==0){ --$j; if($r[$j][2]){ --$r[$j][2]; ++$a[$b[$j]+2]; }elsif($r[$j][1]){ --$r[$j][1]; ++$a[$b[$j]+1]; }elsif($r[$j][0]){ --$r[$j][0]; ++$a[$b[$j]+0]; } } } 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"; }