import scala.io.StdIn._

object Main {
  def transformation(s: String, n: Int, l: List[String] = Nil): List[String] = {
    if (n > 0) {
      val transformType = readLine().split(" ")
      val start = transformType(1).toInt
      val end = transformType(2).toInt + 1
      val to = transformType(2).toInt - start + 1
      transformType(0) match {
        case "print"   => transformation(s, n - 1, l :+ s.slice(start, end))
        case "replace" => transformation(s.patch(start, transformType(3), to), n - 1, l)
        case "reverse" =>
          val reverseText = s.slice(start, end).reverse
          val sReverse = s.patch(start, reverseText, to)
          transformation(sReverse, n - 1, l)
      }
    } else l
  }

  def main(args: Array[String]): Unit = {
    val originText = readLine()
    val transformNum = readInt()
    transformation(originText, transformNum).foreach(println)
  }
}