m@main=getLine>>=putStrLn.f splitAt.words>>m f(!)[a,b,c]=last$c:[d++b++g|i<-[0..200],let(d,e)=i!c;(f,g)=length a!e,a==f]