#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[]) {
  string str, command, p;
  int q, a, b, i;
  cin >> str >> q;

  for (i = 0; i < q; i++) {
    cin >> command >> a >> b;
    if (command == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (command == "replace") {
      cin >> p;
      str = str.replace(a, b - a + 1, p);
    } else {
      reverse(str.begin() + a, str.begin() + b + 1);
    }
  }

  return 0;
}

