'use strict'

const main = arg => {
    var input = arg.trim().split("\n");
    var str = input[0];
    var count = parseInt(input[1], 10);
    var runs = input.slice(2, 2+count);
    runs.forEach(com => {
        const command = com.split(" ");
        const a = parseInt(command[1], 10);
        const b = parseInt(command[2], 10);
        switch(command[0]){
            case "replace":
                str = str.slice(0, a) + command[3] + str.slice(b+1, str.length);
                break;
            case "reverse":
                str = str.slice(0, a) + str.slice(a, b+1).split("").reverse().join("") + str.slice(b+1, str.length);
                break;
            case "print":
                console.log(str.slice(a, b+1));
                break;
        }
    });
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
