//const config = { stdin: 'tmp', newline: '\r\n' }; // win
const config = { stdin: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.stdin, 'ascii').trim()
	.split(config.newline).map(function (line) {
		return line.split(' ');
});
str = line.shift()[0];
line.shift();
res = line.reduce(function (prev, cur) {
	var op = cur[0], a = parseInt(cur[1]), bp1 = parseInt(cur[2]) + 1, ary;
	if (op === 'print') {
		console.log(prev.slice(a, bp1));
		return prev;
	} else if (op === 'reverse') {
		ary = prev.slice(a, bp1).split('');
		ary.reverse();
		return prev.slice(0, a) + ary.join('') + prev.slice(bp1);
	} else {
		return prev.slice(0, a) + cur[3] + prev.slice(bp1);
	}
}, str);