object Main {
    def step(s: String, x: Int, y: Int, cmd: Array[String]) = cmd(0) match {
        case "print" => {println(s.slice(x, y+1)); s}
        case "reverse" => s.take(x) + s.slice(x, y+1).reverse +s.drop(y+1)
        case "replace" => 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)((t, u) => step(t, u(1).toInt, u(2).toInt, u))
    }
}