#include <bits/stdc++.h>
using namespace std;

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

