map{$_=reverse if$s=$$>>$i++&2;$d?$y:$x+=1-$s,$a[$y+7]|=$"x($x+8).$_ for/./g;$d^=1}<>;print uc,$/for@a