import Control.Monad

main = do
  n <- getLine
  q <- readLn
  a <- map words <$> replicateM q getLine
  
  putStrLn $ f True n a
  
f :: Bool -> String -> [[String]] -> String
f b ss [] = ss
f b ss (x:[]) 
  | length x == 1 && b = reverse ss
  | length x == 1 && not b = ss
  | otherwise = f2 b ss x
f b ss (x:xs) 
  | length x == 1 = f (not b) ss xs
  | otherwise = f b (f2 b ss x) xs
  
f2 :: Bool -> String -> [String] -> String
f2 bo s [_,a,b]
  | a == "1" && bo = b ++ s
  | a == "1" && not bo = s ++ b
  | a == "2" && bo = s ++ b
  | a == "2" && not bo = b ++ s 
 
