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

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    s <- getLine
    q <- getInt
    queues <- map words <$> replicateM q getLine
    putStrLn . rev $ foldl solve (True, s) queues

rev (b, s) | b = s
           | not b = reverse s

solve (b, s) queue | queue !! 0 == "1" = (not b, s)
                   | queue !! 1 == "1" && b = (b, (queue !! 2) ++ s)
                   | queue !! 1 == "1" && not b = (b, s ++ (queue !! 2))
                   | queue !! 1 == "2" && b = (b, s ++ (queue !! 2))
                   | queue !! 1 == "2" && not b = (b, (queue !! 2) ++ s)