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