let print str a b =
  String.sub str a (b-a+1) |> print_endline;;
let replace str a b p=
  String.mapi (fun i x -> if a <= i && b >= i then p.[i-a] else x ) str;;
let reverse str a b =
  String.mapi (fun i x -> if a <= i && b >= i then str.[a+b-i] else x) str;;

let split = Str.split (Str.regexp_string " ");;
let () =
  let s = read_line () and
      n = read_int () in
  let rec loop str = function
      0 -> ()
    | i -> let c = read_line () |> split |> Array.of_list in
           let (a,b) = (int_of_string c.(1),int_of_string c.(2)) in
           let result =
             if c.(0) = "replace" then
               replace str a b c.(3)
             else if c.(0) = "reverse" then
               reverse str a b
             else begin
                 print str a b; str
               end
           in loop result (i-1)
  in loop s n;;