import scala.io.Source

object Main {

  def transform(target: String, cmd: Array[String]) = cmd(0) match {
    case "print" => { println(target.slice(cmd(1).toInt, cmd(2).toInt+1)); target }
    case "reverse" => target.take(cmd(1).toInt) + target.slice(cmd(1).toInt, cmd(2).toInt+1).reverse + target.drop(cmd(2).toInt+1)
    case "replace" => target.take(cmd(1).toInt) + cmd(3) + target.drop(cmd(2).toInt+1)
  }

  def main(args: Array[String]): Unit = {
    val src = Source.stdin.getLines
    val target = src.next
    src.next
    src.map(_.split(" ")).foldLeft(target)(transform)
  }

}