for$@(r,u,0,d){$_.=$"x!!$@x9^$@x s/$@/ /ig,s/./$b[$\++].=$&/ge,$\=$/for(@a,@b)=reverse<>,@b}/.*\S/&&print$&for@b