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 $ foldl' solve s queues

solve s queue | queue !! 0 == "1" = reverse s
              | queue !! 1 == "1" = (queue !! 2) ++ s
              | otherwise = s ++ (queue !! 2)