import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    var str = StdIn.readLine()
    val q =  StdIn.readInt()

    for(_ <- 1 to q){

      val line = StdIn.readLine().split(" ")
      val a = line(1).toInt
      val b = line(2).toInt

      line(0) match {
        case "replace" => {
          str = str.patch(a,line(3),b - a + 1)
        }
        case "reverse" => {
          str = str.patch(a,str.slice(a,b + 1).reverse,b - a + 1)
        }
        case "print"   => println(str.slice(a,b + 1))
      }
    }
  }
}