let rev str =
  let len = String.length str in
  let buf = Buffer.create len in
  let rec loop = function
      0 -> Buffer.contents buf
    | i ->
      Buffer.add_char buf str.[i-1];
      loop (i-1)
  in loop len

let () =
  let print str a b = print_endline (String.sub str a (b-a+1)) in
  let replace str a b p =
    let len = String.length str in
    (if a>0 then String.sub str 0 a else "") ^
    p ^
    (if b+1<len then String.sub str (b+1) (len-b-1) else "") in
  let reverse str a b = replace str a b (String.sub str a (b-a+1) |> rev) in
  let rec loop acc = function
      0 -> ()
    | i ->
      let code = Str.split (Str.regexp " ") (read_line ()) in
      let op,a,b = List.nth code 0,
                   List.nth code 1 |> int_of_string,
                   List.nth code 2 |> int_of_string in
      match op with
      | "print" -> print acc a b; loop acc (i-1)
      | "reverse" -> loop (reverse acc a b) (i-1)
      | _ -> let p = List.nth code 3 in
             loop (replace acc a b p) (i-1)
  in 
  let str = read_line () in
  loop str (read_int ())