import Data.Monoid
import Control.Monad
import Data.List

main = do
  s <- getLine
  q <- read <$> getLine
  proc <- replicateM q (words <$> getLine)
  putStrLn $ appEndo (foldr (flip (<>)) mempty $ map parse proc) s

parse ["1"] = Endo reverse
parse ["2", "1", c] = Endo (c<>)
parse ["2", "2", c] = Endo (<>c)