import Control.Monad
import Control.Applicative

slice from to str = take (to - from + 1) (drop from str)

applyOp ["print", as, bs] (str, prt) = (str, prt ++ [result])
    where a = read as
          b = read bs
          result = slice a b str

applyOp ["replace", as, bs, newStr] (str, prt) = (replace a b str newStr, prt)
    where a = read as
          b = read bs
          replace from to str newStr = take from str ++ newStr ++ drop (to + 1) str

applyOp ["reverse", as, bs] (str, prt)= (reverse' a b str, prt)
    where a = read as
          b = read bs
          reverse' from to str = take from str ++ (reverse (slice a b str)) ++ drop (to + 1) str

main = do
    str <- getLine
    nops <- read <$> getLine
    opsStr <- replicateM nops $ words <$> getLine
    let (_, prt) = foldl (flip applyOp) (str, []) opsStr
    mapM_ putStrLn prt