import           Control.Applicative
import           Data.List

print' :: Int -> Int -> String -> String
print' a b xs = take (b - a + 1) $ drop a xs

reverse' :: Int -> Int -> String -> String
reverse' a b xs = l ++ m ++ r
  where
    l = take a xs
    m = reverse $ print' a b xs
    r = drop (b + 1) xs

replace' :: Int -> Int -> String -> String -> String
replace' a b ps xs = l ++ ps ++ r
  where
    l = take a xs
    r = drop (b + 1) xs

doCommands :: String -> [[String]] -> IO ()
doCommands _ [] = return ()
doCommands state ((x:ys):zss)
    | x == "print" = do
        let [a, b] = ys
        putStrLn $ print' (read a) (read b) state
        doCommands state zss
    | x == "reverse" = do
        let [a, b] = ys
        doCommands (reverse' (read a) (read b) state) zss
    | x == "replace" = do
        let [a, b, c] = ys
        doCommands (replace' (read a) (read b) c state) zss

main :: IO ()
main = do
    xs <- getLine
    getLine
    commands <- fmap words . lines <$> getContents
    doCommands xs commands

