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

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