let char_list_of_string str =
  let rec loop i list =
    if i > 0 then loop (i-1) (str.[i-1]::list)
    else list
  in
  loop (String.length str) []
;;                   

let myrev list a b =
  let rdiv list n =
    let rec loop l1 l2 i =
      if i > 0 then
        match l2 with
          [] -> l1,[]
        | hd::td ->  loop (hd::l1) td (i-1)
      else l1,l2
    in
    loop [] list n
  in
  let front, mid, back =
    let x, yz = rdiv list a in
    let y, z = rdiv yz (b-a+1) in
    x, y, z
  in
  let rec reverse_append acu = function
      [] -> acu
    | hd::tl -> reverse_append (hd::acu) tl
  in
  let mid_front =  
    reverse_append front mid
  in
  reverse_append back mid_front
;;

let my_replace str a b p =
  let rec loop str i =
    if i < a then
      match str with
        [] -> []
      | hd::tl -> hd::loop tl (i+1)
    else if i <= b then loop (List.tl str) (i+1)
    else p @ str
  in
  loop str 0
;;

let my_print str a b =
  let rec print_loop i = function
      [] -> ()
    | hd::tl -> if i < a then print_loop (i+1) tl
                else if i < b then (print_char hd;print_loop (i+1) tl)
                else if i = b then (print_char hd;print_char '\n')
                else ()
  in
  print_loop 0 str;;

let () =
  let ch_list =
    let str = read_line () in
    char_list_of_string str
  in
  let q = read_int () in
  let rec loop ch_list = function
      0 -> ()
    | i ->
       let command, a, b, p' = Scanf.sscanf (read_line()) "%s %d %d %s" (fun x y z w ->x,y,z,w) in
       match command with
         "print" ->  my_print ch_list a b;
                     loop ch_list (i-1)
       | "reverse" -> loop (myrev ch_list a b) (i-1)
       | "replace" -> let p =
                        char_list_of_string p'
                      in
                      loop (my_replace ch_list a b p) (i-1)
       | _ -> ()
  in
  loop ch_list q
;;
