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

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