import qualified Data.Sequence as Seq
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 :: String -> Query -> String
applyQuery xs QueryReverse = reverse xs
applyQuery xs (QueryPrepend c) = c:xs
applyQuery xs (QueryAppend c) = xs |> c

optimize :: [Query] -> [Query]
optimize [x] = [x]
optimize [] = []
optimize (x:y:xs) = if x == QueryReverse && y == QueryReverse then optimize xs
  else x:optimize (y:xs)

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