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

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