#include <iostream>
#include <string>
using namespace std;

int main() {
	string str; int n;
	cin >> str; cin >> n;
	while(n--) {
		string op; int a, b;
		cin >> op; cin >> a >> b;
		if(op == "replace") {
			string p;
			cin >> p;
			for(int i = 0; i < b - a + 1; i++) str[a + i] = p[i];
		}
		else if(op == "reverse") {
			for(int i = 0; i < (b - a + 1) / 2; i++) {
				char ch = str[a + i];
				str[a + i] = str[b - i];
				str[b - i] = ch;
			}
		}
		else {
			for(int i = a; i <= b; i++) cout << str[i];
			cout << '\n';
		}
	}
	return 0;
}
