#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	vector<char> str;
	char c;
	while (scanf("%c", &c) != EOF){
		str.push_back(c);
	}
	int n;
	scanf("%d", n);
	while (n--){
		char *require;
		scanf("%s", require);
		if (require == "replace"){
			int a, b;
			char* strings;
			scanf("%d %d %s", &a, &b, strings);
			copy(strings, strings + strlen(strings), str[a]);
		}
		else if (require == "reverse"){
			int a, b;
			scanf("%d %d", &a, &b);
			vector<char> rev;
			copy(str[a], str[b], rev);
			reverse(rev.begin(), rev.end());
			copy(rev[0], rev[rev.size() - 1], str[a]);
		}
		else{
			int a, b,idx;
			scanf("%d %d", &a, &b);
			for (idx = a; idx <= b; idx++){
				printf("%c", str[idx]);
			}
			printf("\n");
		}
	}
}