import Control.Monad

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