main = do
    str <- getLine
    n <- getLine
    oCommands <- getContents
    let commands = map words $ lines oCommands
    runCommand commands str


runCommand [] _ = return ()
runCommand (x:xs) str = do
    let cmd = x!!0
    case cmd of
        "print"   -> do
                         putStrLn $ slice str (read (x!!1) :: Int) (read (x!!2) :: Int)
                         runCommand xs str
        "reverse" -> runCommand xs $ rev str (read (x!!1) :: Int) (read (x!!2) :: Int)
        "replace" -> runCommand xs $ rep str (read (x!!1) :: Int) (read (x!!2) :: Int) (x!!3)

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

rev str from to = (take from str) ++ (reverse (slice str from to)) ++ (drop (to+1) str)

rep str from to nstr = (take from str) ++ nstr ++ (drop (to+1) str)

