import Control.Monad

slice :: String -> Int -> Int -> String
slice s a b = take (b - a + 1) $ drop a s

rev :: String -> Int -> Int -> String
rev s a b = take a s ++ (reverse $ slice s a b) ++ drop (b + 1) s

rep :: String -> Int -> Int -> String -> String
rep s a b p = take a s ++ p ++ drop (b + 1) s

solve :: String -> [String] -> [String]
solve s ss = snd $ foldl (\a l -> f a (words l)) (s, []) ss
    where
        f (s, ss) (o:a:b:xs)
            | o == "print"   = (s, ss ++ [slice s (read a) (read b)])
            | o == "reverse" = (rev s (read a) (read b), ss)
            | o == "replace" = (rep s (read a) (read b) (xs !! 0), ss)

main :: IO ()
main = do
    s  <- getLine
    n  <- readLn
    ss <- replicateM n getLine
    putStr $ unlines $ solve s ss