#include <iostream>
#include <string>
#include <string.h>
#include <cstdio>
#include <cctype>
using namespace std;

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

	cin >> str >> q;
	for(int t=0; t<q; t++){
		cin >> com >> a >> b;
		if(com == "print"){
			cout << str.substr(a,b-a+1) << endl;
		} 
		else if(com == "reverse") {
			string tmp = str.substr(a, b-a+1);
			int n = tmp.size();
			for(int i=0; i<n; i++) str[i+a] = tmp[n-i-1];
		} 
		else if(com == "replace") {
			cin >> p; str = str.replace (a, b-a+1, p);
		}
	}

	return 0;
}
