import Control.Monad.State
import Control.Monad
import Data.List

main = do
    s <- getLine
    q <- getLine >>= return . (read :: String -> Int)
    x <- replicateM q (getLine >>= return . words)
    let (b,c) = (runState $ foldl' (>>=) (return s) (map f x)) True
    if c then putStrLn b else putStrLn (reverse b)

f :: [String] -> String -> State Bool String
f ["1"] s = do
    b <- get
    put $ not b
    return s

f x  s = do
    b <- get
    return (if (x !! 1 == "1") == b then x !! 2 ++ s else s ++ x !! 2)
