main=interact$unlines.map unwords.f.words f x=x:[c:z|a:b:y<-[x],let(c,d)=splitAt(length b)$a++b,z<-f$d:y]