import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

cmdPrint s a b = putStrLn . drop a . take (b+1) $ s
cmdReverse s a b = take a s ++ (reverse .drop a . take (b+1) $ s) ++ drop (b+1) s
cmdReplace s a b p = take a s ++ p ++ drop (b+1) s

exec :: String -> [[String]] -> IO ()
exec s [] = return ()
exec s (["print", a, b]:cs) = cmdPrint s (read a) (read b) >> exec s cs
exec s (["reverse", a, b]:cs) = exec (cmdReverse s (read a) (read b)) cs
exec s (["replace", a, b, p]:cs) = exec (cmdReplace s (read a) (read b) p) cs

main = do
    s <- getLine
    q <- readLn
    cs <- map words <$> replicateM q getLine
    exec s cs