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

int main(void)
{
    string str;
    cin >> str;
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        string temp, temp2;
        int a,b;
        cin >> temp;
        if(temp == "replace"){
            cin >>a>>b>>temp2;
            str.replace(a,b-a+1,temp2);
        }else if(temp == "reverse"){
            cin >>a>>b;
            reverse(str.begin()+a, str.begin()+b+1);
        }else{
            cin >>a>>b;
            cout <<str.substr(a,b-a+1)<<endl;
        }
    }
}
