main = do
  s <- getLine
  _ <- getLine
  ss' <- getContents
  let ss = map words . lines $ ss'
  aux s ss

aux :: String -> [[String]] -> IO()
aux _ [] = return()
aux s (x:xs) = case (head x) of
  "print" -> let a = read (x!!1)
                 b = read (x!!2) in do
                     putStrLn $ substr a (b+1) s 
                     aux s xs 
  "reverse" ->  let a = read (x!!1)
                    b = read (x!!2) in
                aux ((take a s)++(reverse . substr a (b+1) $ s) ++(drop (b+1) s)) xs
  "replace" ->  let a = read (x!!1)
                    b = read (x!!2)
                    p = x!!3 in
                aux ((take a s)++p++(drop (b+1) s)) xs
  _        ->   aux s xs                


substr :: Int -> Int -> String -> String
substr n m s =  drop n . take m $ s 