import scala.io.Source

object Main {

  def transform(src: Iterator[String], target: String, n: Int): String = {
    if (n <= 0) target
    else {
      val Array(action, start, end, sub @ _*) = src.next.split(" ")
      if (action == "replace") transform(src, target.patch(start.toInt, sub.head, end.toInt - start.toInt + 1), n-1)
      else if (action == "reverse") transform(src, reversePartially(start.toInt, end.toInt, target), n-1)
      else transform(src, printPartially(start.toInt, end.toInt, target), n-1)
    }
  }

  def reversePartially(start: Int, end: Int, str: String): String = {
    val reversedPart = str.take(end+1).drop(start).reverse
    str.patch(start, reversedPart, end - start +1 )
  }

  def printPartially(start: Int, end: Int, str: String): String = {
    val printPart = str.take(end+1).drop(start)
    println(printPart)
    printPart
  }

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

    val src = Source.stdin.getLines
    val target = src.next
    val numOfLines = src.next.toInt

    transform(src, target, numOfLines)
  }

}