let hd x i = String.sub x 0 i ;;
let md x i j = String.sub x i (j + 1 - i) ;;
let tl x i j = String.sub x (j+1) (String.length x - 1 - j);;

let replace x y i j = hd x i ^ y ^ tl x i j;;
let reverse x i j  =
  let rec rev s k res =
    if k = String.length s then List.fold_left (fun e x -> e ^ x) "" res
    else rev s (k+1) ((String.sub s k 1) :: res)
  in
  hd x i ^ rev (md x i j) 0 [] ^ tl x i j ;;
let print x i j = print_endline (md x i j) ;;

let () =
  let str = read_line() in
  let m = read_int() in
  let rec loop line n =
    if n = 0 then ()
    else
      let lst = Str.split (Str.regexp " ") (read_line()) in
      let i = int_of_string (List.nth lst 1) in
      let j = int_of_string (List.nth lst 2) in
      try
        (match List.hd lst with
          "replace" -> let r = List.nth lst 3 in loop (replace line r i j) (n-1)
        | "reverse" -> loop (reverse line i j) (n-1)
        | _ -> raise Not_found)
      with Not_found -> print line i j ; loop line (n-1) 
  in
  loop str m ;;
