import Control.Monad
import Data.List

processes :: String -> [[String]] -> String
processes s [] = s
processes s (x:xs)
   | x == ["1"] && xs == []         = reverse s
   | x == ["1"] && head xs == ["1"] = processes s (tail xs)
   | x == ["1"]                     = reverse $ processes s xs
   | x !! 0 == "2" && x !! 1 == "1" = (x !! 2) ++ (processes s xs)
   | x !! 0 == "2" && x !! 1 == "2" = (processes s xs) ++ (x !! 2)

main = do
   s <- getLine
   q <- read <$> getLine
   qs <- replicateM q $ words <$> getLine
   putStrLn $ processes s qs