process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

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

reader.on("close", () => {
  let s = lines[0];
  const n = Number(lines[1]);
  for (let i = 2; i < n + 2; i++) {
    const ts = lines[i].split(" ");
    const a = Number(ts[1]);
    const b = Number(ts[2]);
    switch (ts[0]) {
      case "replace":
        s = s.slice(0, a) + ts[3] + s.slice(b + 1);
        break;
      case "reverse":
        s =
          s.slice(0, a) +
          s
            .slice(a, b + 1)
            .split("")
            .reverse()
            .join("") +
          s.slice(b + 1);
        break;
      case "print":
        console.log(s.slice(a, b + 1));
        break;
    }
  }
});

