import Control.Monad (replicateM)
import qualified Data.ByteString.Char8 as BS

main = do
  s <- getLine
  q <- readLn
  qn <- replicateM q (BS.words <$> BS.getLine)
  let p = foldl (\acc p -> case p of
            ["2","1",c] -> c ++ acc
            ["2","2",c] -> acc ++ c
            _ -> reverse acc) s qn
  putStrLn $ p