#include <iostream>
#include <string>

using namespace std;

int main() {

    string str;
    int n;

    cin >> str;
    cin >> n;

    while (n-- > 0) {

        string q, p;
        int a, b, size;

        cin >> q;
        cin >> a >> b;
        size = b - a + 1;

        if (q == "print") {
            cout << str.substr(a, size) << endl;
        } else if (q == "reverse") {
            string sub = str.substr(a, size);
            for (int i = a, i_ = sub.length() - 1; i_ < sub.length(); ++i, --i_) {
                str[i] = sub[i_];
            }
        } else {
            cin >> p;
            str.replace(a, size, p);
        }
    }
}
#include<iostream>
using namespace std;

string rep(string s,int a,int b,string p);
string rev(string s,int a,int b);
void pri(string s,int a,int b);

int main(){
        string code,k,p;
        int n,a,b;
        string haki;
        getline(cin,code);
        cin >> n;
        getline(cin, haki);
        for(int i = 0; i < n; i++){
                cin >> k;
                if(k == "replace"){
                        cin >> a >> b >> p;
                        code = rep(code ,a,b,p);
                }else if(k == "reverse"){
                        cin >> a >> b;
                        code =rev(code , a,b);
                }else if(k == "print"){
                        cin >> a >> b;
                        pri(code, a,b);
                }
                getline(cin,haki);
        }
}

string rep(string s,int a, int b, string p){
        for(int i = a; i <=b; i++){
                s[i] = p[i-a];
        }
        return s;
}string rev(string s, int a, int b){
        string p = s;
        for(int i = a; i <= b; i++){
                s[i] = p[b-i+a];
        }
        return s;
}
void pri(string s, int a, int b){
        for(int i = a; i <= b;i++){
                cout <<s[i];
        }
        cout << endl;
}
