import std.stdio, std.string, std.array, std.conv, std.algorithm;

void main() {
    string str = readln.chomp;
    int n = readln.chomp.to!int;
    int a, b;
    foreach (i; 0 .. n) {
        string[] tmp = readln.chomp.split;
        a = tmp[1].to!int, b = tmp[2].to!int + 1;
        if (tmp[0] == "print") {
            str[a..b].writeln;
        } else if (tmp[0] == "reverse") {
            str = str[0..a] ~ str[a..b].to!(char[]).reverse.to!string ~ str[b..$];
        } else {
            str = str[0..a] ~ tmp[3] ~ str[b..$];
        }
    }
}
