import Control.Monad
import qualified Data.ByteString.Char8 as BS

main = do
  n <- BS.getLine
  q <- readLn
  a <- map BS.words <$> replicateM q BS.getLine
  
  putStrLn $ BS.unpack $ f True n a
  
f b ss [] 
  | b = ss
  | otherwise = BS.reverse ss
f b ss (x:xs) 
  | length x == 1 = f (not b) ss xs
  | otherwise = f b (f2 b ss x) xs
  
f2 b s [_,x,y]
  | BS.elem '1' x && b = BS.append y s
  | BS.elem '1' x && not b = BS.append s y
  | BS.elem '2' x && b = BS.append s y
  | otherwise = BS.append y s
 
