import Control.Monad.State
import Data.List

main :: IO ()
main = fmap fst $ runStateT stateIO ""

stateIO :: StateT String IO ()
stateIO = do
  str <- lift $ getLine
  q <- lift $ readLn

  put str

  replicateM_ q $ do
    (q:qs) <- fmap words $ lift getLine

    s <- get

    case q of
      "replace" -> do
        let
          [a,b] = map read $ init qs
          p = last qs
          (t,r) = splitAt a s
          (_,r2) = splitAt (b-a+1) r
        put $ t ++ p ++ r2
      "reverse" -> do
        let 
          [a,b] = map read qs
          (t,r) = splitAt a s
          (r1,r2) = splitAt (b-a+1) r
        put $ t ++ reverse r1 ++ r2
      "print" -> let
          [a,b] = map read qs
          (_,r) = splitAt a s
          (r1,_) = splitAt (b-a+1) r
        in lift $ putStrLn r1