import List main=interact$unlines.f.lines f(w:x)=x%w%w x%w=transpose[y#w#reverse w|y<-x] (a:s)#w@(_:t)|t++(s\\t)==s=' ':s#t|1>0=a:s#w x#_=x