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

main = abc158D

abc158D :: IO()
abc158D = do
  s <- BS.getLine
  [q] <- getIntList
  qs <- map BS.words <$> replicateM (fromIntegral q) BS.getLine
  putStrLn . BS.unpack $ operation s True qs 

type Query = [BS.ByteString]
operation :: BS.ByteString -> Bool -> [Query] -> BS.ByteString
operation s b [q] = let executed = exec s b $ map BS.unpack q
                    in if snd executed then fst executed else BS.reverse . fst $ executed
operation s b (q:qs) = let executed = exec s b $ map BS.unpack q
                       in operation (fst executed) (snd executed) qs

exec :: BS.ByteString -> Bool -> [String] -> (BS.ByteString, Bool)
exec s b [['1']] = (s,not b)
exec s True [['2'],[x],[c]] = case x of '1' -> (BS.cons c s, True)
                                        '2' -> (BS.pack (BS.unpack s ++ [c]), True)
exec s False [['2'],[x],[c]] = case x of '1' -> (BS.pack (BS.unpack s ++ [c]), False)
                                         '2' -> (BS.cons c s, False)

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine