#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main()
{
	string s;
	int q;
	cin >> s >> q;
	cin.ignore();
	
	string buf;
	while (q)
	{
		getline(cin, buf);
		
		//cout << "DEBUG:" << buf << endl;
		
		if (buf.find("replace ") != string::npos)
		{
			char cmd[10] = {0};
			int a1, a2;
			char a3[1001] = {0};
			sscanf(buf.c_str(), "%s %d %d %s", cmd, &a1, &a2, a3);
			s.replace(a1, (a2+1)-a1, string(a3));
			//cout << "DEBUG:replaced:" << s << endl;
		}
		else if (buf.find("reverse ") != string::npos)
		{
			char cmd[10] = {0};
			int a1, a2;
			sscanf(buf.c_str(), "%s %d %d", cmd, &a1, &a2);
			string sub = s.substr(a1, (a2+1)-a1);
			//cout << "DEBUG:sub( ):" << sub << endl;
			reverse(sub.begin(), sub.end());
			//cout << "DEBUG:sub(r):" << sub << endl;
			size_t subsize = sub.size();
			for (int i = a1, j = 0; i < a1 + subsize; i++, j++) {
				s[i] = sub[j];
			}
			//cout << "DEBUG:reversed:" << s << endl;
		}
		else if (buf.find("print ") != string::npos)
		{
			char cmd[10] = {0};
			int a1, a2;
			sscanf(buf.c_str(), "%s %d %d", cmd, &a1, &a2);
			cout << s.substr(a1, (a2+1)-a1) << endl;
		}
		q--;
	}
	
	return 0;
}
#include <iostream>
#include <string>
using namespace std;

string reverse_partial(string str, int s, int e) {
    string top = s != 0 ? str.substr(0, s - 1) : "";
    string head = str.substr(s, e - s + 1);
    string tail = str.substr(e + 1, str.size());
    string reverse = "";
    for (int i=head.size()-1; i >= 0; i--) {
        reverse += head[i];
    }
    return (top + reverse + tail);
}

int main () {
    string str;
    cin >> str;
    int q;
    cin >> q;

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