import std.stdio, std.string, std.conv;
void main() {
	string s = readln.chomp;
	readln;
	foreach (string l; lines(stdin)) {
		auto d = l.chomp.split;
		auto n = d[1..3].to!(int[]);
		if (d[0] == "print")
			s[n[0]..n[1]+1].writeln;
		if (d[0] == "reverse") {
			auto r = s[n[0]..n[1]+1].to!(char[]).reverse.to!string;
			s = s[0..n[0]] ~ r ~ s[n[1]+1..$];
		}
		if (d[0] == "replace")
			s = s[0..n[0]] ~ d[3] ~ s[n[1]+1..$];
	}
}