import System.IO

main = do
  s <- getLine
  q <- readLn
  hSetBuffering stdout LineBuffering 
  handleQueries (foldr (:) s) False q
  hFlush stdout

handleQueries :: (String -> String) -> Bool -> Int -> IO ()
handleQueries s True 0 = putStrLn $ reverse (s [])
handleQueries s False 0 = putStrLn $ (s [])
handleQueries s b n = do
  t <- words <$> getLine
  case t of
    ["1"] -> handleQueries s (not b) (n -1)
    ["2", "1", (c:_)]
      | b -> handleQueries (s . (c:)) b (n -1 )
      | otherwise -> handleQueries ((c:) . s) b (n -1 )
    ["2", "2", (c:_)]
      | not b -> handleQueries (s . (c:)) b (n -1 )
      | otherwise -> handleQueries ((c:) . s) b (n -1 )
