object Main {
    def step(s: String, cmd: Array[String]) = (cmd(0), cmd(1).toInt, cmd(2).toInt) match {
        case ("print", x, y) => {println(s.slice(x, y+1)); s}
        case ("reverse", x, y) => s.take(x) + s.slice(x, y+1).reverse +s.drop(y+1)
        case ("replace", x, y) => s.patch(x, cmd(3), y-x+1)
    }
    def main(args: Array[String]): Unit = {
        val in = io.Source.stdin.getLines
        val s = in.next
        in.next
        in.map(_.split(" ")).foldLeft(s)(step)
    }
}