import Control.Monad (replicateM)

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