import Control.Monad

type Op = [String]

processTransform :: String -> [Op] -> IO String
processTransform str [] = do return str
processTransform str (op:ops) = do
  nextStr <- transformation str op
  processTransform nextStr ops

transformation :: String -> Op -> IO String
transformation str ["print", sa, sb] = do
  let [a, b] = map read [sa, sb]
  putStrLn $ take (b-a+1) . drop a $ str
  return str
transformation str ["reverse", sa, sb] = do
  let [a, b] = map read [sa, sb]
  return ((take a str) ++ (reverse $ take (b-a+1) . drop a $ str) ++ (drop (b+1) str))
transformation str ["replace", sa, sb, p] = do
  let [a, b] = map read [sa, sb]
  return ((take a str) ++ p ++ (drop (b+1) str))

main :: IO ()
main = do
  str <- getLine
  n <- readLn
  oplist <- replicateM n $ fmap words getLine
  processTransform str oplist
  return ()