compute s e []     = s ++ (reverse e)
compute s e (l:ls) =  if l!!0 == "1"
                      then compute e s ls
                      else if l!!1 == "1"
                           then compute (l!!2 ++ s) e ls
                           else compute s (l!!2 ++ e) ls

main = do
  s <- getLine
  q <- getLine
  ls <- lines <$> getContents
  let qs = map words $ ls
  putStrLn $ compute s "" qs