#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  string str, order, p;
  int a, b, q;

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

  return 0;
}

