import Control.Monad


main = do
  n <- getLine
  q <- readLn
  a <- map words <$> replicateM q getLine

  putStrLn $ f2 n $ foldl f (True, "", "") a

f :: (Bool, String, String) -> [String] -> (Bool, String, String)
f (flag, l, r) [c1]
  | c1 == "1" = (not flag, l, r)
f (flag, l, r) [c1, c2, c]
  | flag && c2 == "1" = (flag, c ++ l, r)
  | flag && c2 == "2" = (flag, l, r ++ c)
  | not flag && c2 == "1" = (flag, l, r ++ c)
  | otherwise = (flag, c ++ l, r)

f2 :: String -> (Bool, String, String) -> String
f2 n (f, l, r)
  | f = l ++ n ++ r
  | otherwise = reverse r ++ n ++ reverse l



