data Query = QueryReverse | QueryPrepend Char | QueryAppend Char

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]

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