import Control.Applicative
import Data.Function
import Control.Monad
import Data.List
import Data.Char
import Control.Monad.State

main :: IO ()
main = do
    str <- getLine
    q <- readLn
    cs <- replicateM q (words <$> getLine)
    (`evalStateT` str) $ forM_ cs $ \c -> do
        let   cmd = c !! 0
              a = read $ c !! 1
              b = read $ c !! 2

        s <- get
        case cmd of
            "replace" -> put $ take a s ++ (c !! 3) ++ drop (a+b) s
            "reverse" -> put $ take a s ++
                         (reverse $ take (b+1) . drop a $ s) ++ drop (a+b+1) s
            "print"   -> lift $ putStrLn $ take (b+1) . drop a $ s
            otherwise -> return ()
    return ()
