m@main=getLine>>=putStrLn.last.f[0..165]drop.words>>m f z(%)[a,b,s]=s:[take x s++b++y%s|x<-z,y<-z,x%s==a++y%s]