import Control.Monad

processes :: [String] -> String -> String
processes q s
   | q == []            = s
   | read (head q) == 1 = reverse s
   | read (q !! 1) == 1 = (q !! 2) ++ s
   | read (q !! 1) == 2 = s ++ (q !! 2)

main = do
   s <- getLine
   q <- read <$> getLine
   qs <- replicateM q $ words <$> getLine
   putStrLn $ foldr (processes) s $ reverse qs