"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

var re = /\s+|$/;
reader.on('close', () => {
    var line = lines.shift();
    const s = line;
    let n = parseInt(lines.shift());
    let cmds = [];
    for (var i=0; i<n; i++) {
	cmds.push(lines.shift().split(/\s/));
    }
    aux(s,cmds);
    //console.log(aux(a,b,c));
});

function aux(s,cmds)
{
    while (cmds.length>0) {
	let cmd = cmds.shift();
	let op = cmd[0];
	let a = parseInt(cmd[1]);
	let b = parseInt(cmd[2]);
	let p = cmd[3];
	let len =s.length;
	//console.log('s: ',s);
	if (op === "print") {
	    console.log(s.slice(a,b+1));
	} else if (op === "reverse") {
	    s = s.slice(0,a) + s.slice(a,b+1).split('').reverse().join('') + s.slice(b+1,len);
	} else if (op === "replace") {
	    s = s.slice(0,a) + p + s.slice(b+1,len);
	} else {
	    console.log("no such command: "+op);
        }
    }

    return(s);
}
