import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  val l = readLine
  val n = readInt

  def transform(i:Int,w:String):Unit = {
    if(i>0) {
      val op = readLine.split(" ")
      val start=op(1).toInt
      val end=op(2).toInt

      (op(0)) match {
        case "replace" => transform(i-1,(w take start) + op(3) + (w takeRight (w.length-end-1)))
        case "reverse" => transform(i-1,(w take start) + (w.slice(start,end+1).reverse) + (w takeRight (w.length-end-1)))
        case "print" => println(w.slice(start, end+1));transform(i-1,w)
      }
    }
  }

  transform(n,l)
}