import Control.Monad

runOperate :: [String] -> String -> IO String
runOperate ["print",   a, b] str = (putStrLn $ take (b' + 1) $ drop a' str) >> (return str)
  where a' = read a; b' = read b
runOperate ["reverse", a, b] str = return $ take a' str ++ (reverse ((take (b' + 1) . drop a') str)) ++ drop (a' + b' + 1) str
  where a' = read a; b' = read b
runOperate ["replace", a, b, sub] str = return $ take a' str ++ sub ++ drop (a' + b') str
  where a' = read a; b' = read b

main :: IO ()
main = do
  str <- getLine
  n <- readLn
  operates <- fmap (map words) $ replicateM n getLine
  foldl (\x y -> x >>= runOperate y) (return str) operates
  return ()