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

using namespace std;

int main () {
    // input
    string str;
    cin >> str;

    int q;
    cin >> q;

    string result = str;
    int res_len = result.length();
    for (int i=0; i<q; i++) {
        string order;
        int a, b;
        cin >> order >> a >> b;
        if (order == "print") {
            // output
            cout << result.substr(a, b-a+1) << endl;
        } else if (order == "reverse") {
            string reversed = "";
            for (int j=0; j<a; j++) {
                reversed += result[j];
            }
            for (int jj=b; jj>a-1; jj--) {
                reversed += result[jj];
            }
            for (int jjj=b+1; jjj<res_len; jjj++) {
                reversed += result[jjj];
            }
            result = reversed;
            //cout << reversed << endl;
        } else if (order == "replace") {
            string p;
            cin >> p;
            string replaced = "";
            for (int k=0; k<a; k++) {
                replaced += result[k];
            }
            for (int kk=a; kk<b+1; kk++) {
                replaced += p[kk-a];
            }
            for (int kkk=b+1; kkk<res_len; kkk++) {
                replaced += result[kkk];
            }
            result = replaced;
            //cout << result << endl;
        }
    }
}

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

using namespace std;


int main(){

	string str1,str2,p;
	char x;
	int q,a,b;

	getline(cin, str1);
	cin >> q;

	for (int i = 0; i < q; i++){
	
		cin >> str2;
		if (str2 == "replace"){
		//replace?????????
			cin >> a >> b >> p;
			for (int j = 0; j < p.length(); j++)
				str1[j + a] = p[j];
		}
	    else if(str2 == "reverse"){
			//reverse?????????
			cin >> a >> b;
			//a???????????????b???????????????????????????

			for (int j = a; j < ((b - a) / 2)+a+1; j++){
			
				swap(str1[j],str1[b-(j-a)]);

			}



		}
		 else if(str2=="print"){
		//print?????????
			cin >> a >> b;
			for (int j = a; j < b+1; j++){
				cout << str1[j];
			}cout << endl;
		 }
	}//??????????????????






	return 0;
}