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

parseCommand :: [String] -> (String -> String)
parseCommand (xs:yss)
    | xs == "print" =
        let [a, b] = yss
         in print' (read a) (read b)
    | xs == "reverse" =
        let [a, b] = yss
         in reverse' (read a) (read b)
    | xs == "replace" =
        let [a, b, c] = yss
         in replace' (read a) (read b) c

main :: IO ()
main = do
    xs <- getLine
    getLine
    commands <- fmap (parseCommand . words) . lines <$> getContents
    let answer = foldl' (\acc cmd -> cmd acc) xs commands
    putStrLn answer

