import Control.Monad

slice a b str = take (b - a + 1) . drop a $ str

parseInsts str [] = return ()
parseInsts str (i:is) = do
  let op = i !! 0
  let a = read (i !! 1) :: Int
  let b = read (i !! 2) :: Int
  when (op == "print") $ do
    putStrLn $ slice a b str
    parseInsts str is
  when (op == "reverse") $ do
    let str1 = take a str ++ (reverse . slice a b) str ++ drop (a + b + 1) str
    parseInsts str1 is
  when (op == "replace") $ do
    let sub = i !! 3
    let str1 = take a str ++ sub ++ drop (a + b) str
    parseInsts str1 is
  
main = do
  str <- getLine
  q <- readLn
  insts <- replicateM q $ return . words =<< getLine
  print insts
  parseInsts str insts