{-# LANGUAGE ScopedTypeVariables #-}
  
import           Control.Monad
import           Data.Foldable
import qualified Data.Sequence as S
import           Data.Sequence ( Seq(..), (<|), (|>) )

data Direction = L | R
  deriving (Eq)

data Query = Reverse | InsertHead Char | AppentLast Char

main :: IO ()
main = do
  s <- S.fromList <$> getLine
  q <- readLn
  qs <- replicateM q readQuery
  putStrLn $ toList $ solve s L qs

solve :: Seq Char -> Direction -> [Query] -> Seq Char
solve s d qs = case go s d qs of
  (s1, L) -> s1
  (s1, R) -> S.reverse s1
  where
    go s d []                  = (s, d)
    go s d (Reverse      : qs) = go s (changeDirection d) qs
    go s d (InsertHead c : qs)
      | d == L                 = go (c <| s) L qs
      | d == R                 = go (s |> c) R qs
    go s d (AppentLast c : qs)
      | d == L                 = go (s |> c) L qs
      | d == R                 = go (c <| s) R qs

changeDirection :: Direction -> Direction
changeDirection L = R
changeDirection R = L

readQuery :: IO Query
readQuery = do
  q <- getLine
  case map head (words q) of
    ['1']         -> return $ Reverse
    ['2', '1', c] -> return $ InsertHead c
    ['2', '2', c] -> return $ AppentLast c