let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let print str a b =
  let rec doit i =
    if i > b then print_newline ()
    else begin
      print_char (String.get str i);
      doit (i + 1);
    end
  in
  doit a; str

let reverse str a b =
  let n = String.length str in
  let rec doit i ret =
    if i >= n then ret
    else
      let j = if i >= a && i <= b then b + a - i else i in
      doit (i + 1) (ret ^ (Char.escaped (String.get str j)))
  in
  doit 0 ""

let replace str a b p =
  String.sub str 0 a ^ p ^ String.sub str (b + 1) (String.length str - 1 - b)

let () =
  let str = read_line () in
  let n = read_int () in
  let rec doit i str =
    if i > n then ()
    else
      let l = read_line () in
      match split l ' ' with
      | [] | [_] | _::_::[] -> exit 1
      | "print" :: a :: b :: _ -> doit (i + 1) (print str (int_of_string a) (int_of_string b))
      | "reverse" :: a :: b :: _ -> doit (i + 1) (reverse str (int_of_string a) (int_of_string b))
      | "replace" :: a :: b :: p :: _ -> doit (i + 1) (replace str (int_of_string a) (int_of_string b) p)
      | _ -> exit 1
  in
  doit 1 str