#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
    
    int i, j, n;
    string s, r, cmd;
    cin >> s;
    cin >> n;
    while (n--) {
        cin >> cmd >> i >> j;
        if (cmd == "print") cout << s.substr(i, (j - i + 1)) << "\n";
        else if (cmd == "reverse") reverse(s.begin() + i, s.begin() + j + 1);
        else {
            cin >> r;
            s.replace(i, (j - i + 1), r);
        }
    }
    
    return 0;
}

