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

object Main extends App {
  var str = readLine
  val n = readInt

  for (_ <- 1 to n) {
    val input = readLine.split(" ").map(e => try {
      e.toInt
    } catch {
      case _: Exception => e
    })
    if (input.length == 4) {
      val Array(order: String, pos1: Int, pos2: Int, replaceStr: String) = input
      str = executeOrder(order, pos1, pos2, replaceStr)
    } else {
      val Array(order: String, pos1: Int, pos2: Int) = input
      str = executeOrder(order, pos1, pos2)
    }

    def executeOrder(order: String, pos1: Int, pos2: Int, replaceStr: String = ""): String = {
      val partialString = str.slice(pos1, pos2 + 1)
      order match {
        case s if s == "print" => println(partialString); str
        case s if s == "replace" => str.patch(pos1, replaceStr, pos2 - pos1 + 1).mkString
        case s if s == "reverse" => str.patch(pos1, partialString.reverse, pos2 - pos1 + 1).mkString
      }
    }
  }
}
