main=interact$(>>=unlines.f).lines f('d':_:x)=f x!!0:f x f x=[x]