import std.array : replaceInPlace;
import std.algorithm.mutation : reverse;
import std.stdio : readf, writeln;

void main() {
  char[] s;
  readf!"%s\n"(s);
  size_t q;
  readf!"%d\n"(q);
  foreach (_; 0 .. q) {
    string c;
    size_t a, b;
    readf!"%s "(c);
    switch (c) {
      case "print":
        readf!"%d %d\n"(a, b);
        writeln(s[a .. b + 1]);
        break;
      case "reverse":
        readf!"%d %d\n"(a, b);
        reverse(s[a .. b + 1]);
        break;
      case "replace":
        char[] p;
        readf!"%d %d %s\n"(a, b, p);
        s.replaceInPlace(a, b + 1, p);
        break;
      default:
        break;
    }
  }
}