import qualified Data.Sequence as S
import Data.IORef
import Control.Monad
import Data.Foldable

readInput :: Read a => IO [a]
readInput = map read . words <$> getLine

main = do
    refStr <- getLine >>= newIORef . S.fromList
    count <- readLn
    replicateM_ count $ do
        input <- words <$> 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 >>= putStrLn . toList