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

oper :: String -> [String] -> String -> ( String, String )
oper "print"   (p1:p2:_)    str = ( str, (take (b-a+1).drop a)str ++ "\n" ) where (a,b) = (read p1, read p2)
oper "reverse" (p1:p2:_)    str = ( take a str ++ reverse((take (b-a+1).drop a) str) ++ drop (b+1) str, "") where (a,b) = (read p1, read p2)
oper "replace" (p1:p2:p3:_) str = ( take a str ++ p3 ++ drop (b+1) str, "") where (a,b) = (read p1, read p2)

run :: [[String]] -> String -> (String, String)
run [] str = (str,"")
run (x:xs) str = ( tstr, prt' ++ tprt)
                 where (str', prt') = run xs str
                       (tstr, tprt) = oper (x!!0) (drop 1 x) str'

main = do
    str <- getLine
    q <- readLn ::IO Int
    s <- replicateM q (words <$> getLine) :: IO [[String]]
    --let tstr = "0123456789"
    --let tscr = [["print"],["reverse" , "1", "3"],["print"],["replace","3","7","AAAAA"],["print"]]
    
    putStrLn $ snd (run (reverse s) str)
    