import Control.Monad
import Data.List

processes :: String -> [String] -> String
processes s q
   | 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 $ foldl' (processes) s qs