import Data.Functor( (<$>))
import Control.Monad( replicateM, foldM_)

main = do
    initialStr <- getLine
    q <- read <$> getLine
    operations <- replicateM q getLine
    let
	partitionizeWith a b f str
	  = let
		(left,part3) = splitAt (b+1) str
		(part1,part2) = splitAt a left
	    in
		part1 ++ f part2 ++ part3

	proc str operation
	  = let
		ops = words operation
		a = read $ ops!!1
		b = read $ ops!!2
	    in
		case ops!!0 of
		"print"	   -> let s = drop a  $ take (b+1) str
				in putStrLn s >> return str
		"reverse"  -> return $ partitionizeWith a b reverse str
		"replace"  -> return $ partitionizeWith a b (const $ ops!!3) str

    foldM_ proc initialStr operations

