main = do
  s <- getLine
  q <- readLn
  handleQueries (foldr (:) s) False q

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 <- 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 )