#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	string s,d,n;
	int h,a,b;
	cin >> s >> h;
	for(int i = 0; i < h; i++){
		cin >> d >> a >> b;
		if(d[2] == 'i'){
			cout << s.substr(a,b - a + 1) << endl;
		}
		else if(d[2] == 'v'){
			reverse(s.begin() + a, s.begin() + b + 1);
		}
		else{
			cin >> n;
			s.replace(a,b - a + 1,n);
		}
	}
	return 0;
}
