const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
let str = input[0].split('');
let time = Number(input[1]);

for (let i=2; i<time+2; i++) {
    let order = input[i].split(' ');
    let a = Number(order[1]);
    let b = Number(order[2]);
    if (order[0] === 'replace') {
      let word = order[3].split('');
      str.splice(a, b+1-a, ...word);
    }
    if (order[0] === 'reverse') {
        word = str.slice(a, b+1);
        word.reverse();
        str.splice(a, b+1-a, ...word)
    }
    if (order[0] === 'print') {
        word = str.slice(a, b+1);
        console.log(word.join(''));
    }

}
