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

sealed trait Order
case class Print(a: Int, b: Int)              extends Order
case class Reverse(a: Int, b: Int)            extends Order
case class Replace(a: Int, b: Int, p: String) extends Order

object Main extends App {
  val str    = readLine()
  val n      = readInt()
  val lines  = Iterator.fill(n)(readLine())
  val orders = lines.map { _.split(" ") }.map {
    case Array("print", a, b)      => Print(a.toInt, b.toInt)
    case Array("reverse", a, b)    => Reverse(a.toInt, b.toInt)
    case Array("replace", a, b, p) => Replace(a.toInt, b.toInt, p)
  }

  val printStrings = {
    val (_, printStrings) = orders.foldLeft((str, Nil: List[String])) { (accum, order) =>
      val (s, printStrings) = accum
      order match {
        case Print(a, b)      =>
          val ps = s.slice(a, b + 1)
          (s, ps :: printStrings)
        case Reverse(a, b)    =>
          val rev = s.slice(a, b + 1).reverse
          (s.patch(a, rev, b - a + 1), printStrings)
        case Replace(a, b, p) =>
          (s.patch(a, p, b - a + 1), printStrings)
      }
    }
    printStrings.reverse
  }

  printStrings.foreach(println)
}

