{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Sequence as S
import Data.IORef
import Control.Monad
import Data.Foldable
import qualified Data.ByteString.Char8 as B

main = do
    refStr <- B.getLine >>= newIORef . S.fromList . pure
    count <- readLn
    replicateM_ count $ do
        input <- B.words <$> B.getLine
        case input of
            "1" : _ -> do
                modifyIORef' refStr S.reverse
            "2" : end : chr : _ -> 
                if end == "1"
                    then modifyIORef' refStr (chr S.<|)
                    else modifyIORef' refStr (S.|> chr)
    readIORef refStr >>= B.putStrLn . mconcat . toList