import Data.List
import qualified Data.Sequence as Seq
import Data.Foldable


data Query = QueryReverse | QueryPrepend Char | QueryAppend Char deriving Eq

convertToQueryData :: [String] -> Query
convertToQueryData [_] = QueryReverse
convertToQueryData (_:f:c:_) = if (read f :: Integer) == 1 then QueryPrepend $ head c
  else QueryAppend $ head c

applyQuery :: Seq.Seq Char -> Query -> Seq.Seq Char
applyQuery xs QueryReverse = Seq.reverse xs
applyQuery xs (QueryPrepend c) = c Seq.<| xs
applyQuery xs (QueryAppend c) = xs Seq.|> c

main :: IO ()
main = do
  line <- getLine
  let lineSeq = Seq.fromList line
  nQueriesStr <- getLine
  let nQueries = read nQueriesStr
  stringQueries <- sequence $ take nQueries $ repeat getLine
  let queries = map (convertToQueryData . words) stringQueries
  putStrLn (toList (foldl' (\ac query -> applyQuery ac query) lineSeq queries))
