#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t, r;
	int n, a, b;
	cin >> s >> n;
	for (int i = 0; i < n; i++) {
		cin >> t >> a >> b;
		if (t == "print")
			cout << s.substr(a, b - a + 1) << endl;
		else if (t == "reverse")
			for (int j = 0; j < (b - a + 1) / 2; j++)
				swap(s[a + j], s[b - j]);
		else {
			cin >> r;
			s.replace(a, b - a + 1, r);
		}
	}
}
// class point	の練習（クラスの高度な実装）
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>

typedef long long llong;
using namespace std;

int main() {
	char strin[1010];
	int a, b;
	int q;
	char querin[10];
	char repin[1100];
	char revin[1100];

	scanf("%s", strin);
	getchar();
	cin >> q;
	for (int i = 0; i < q; i++) {
		scanf("%s %d %d", querin, &a, &b);
		if (!strcmp(querin, "replace")) {
			scanf("%s", repin);
			for (int j = a; j <= b; j++) {
				strin[j] = repin[j - a];
			}
		}
		else if (!strcmp(querin, "print")) {
			for (int j = a; j <= b; j++) {
				printf("%c", strin[j]);
			}
			cout << '\n';
		}
		else if (!strcmp(querin, "reverse")) {
			for (int j = a; j <= b; j++) {
				revin[j - a] = strin[j];
			}
			for (int j = b; j >= a; j--) {
				strin[a + b - j] = revin[j - a];
			}
		}
	}

	return 0;
}

