object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    var str = scanner.next
    val q = scanner.nextInt
    for(_ <- 1 to q) {
      scanner.next match {
        case "print" => println(str.substring(scanner.nextInt, scanner.nextInt + 1))
        case "reverse" => str = reverse(str, scanner.nextInt, scanner.nextInt)
        case _ => str = replace(str, scanner.nextInt, scanner.nextInt, scanner.next)
      }
    }
  }

  def reverse(str: String, a: Int, b: Int): String =
    str.substring(0, a) + str.substring(a, b + 1).reverse + str.substring(b + 1, str.length)

  def replace(str: String, a: Int, b: Int, p: String): String =
    str.substring(0, a) + p + str.substring(b + 1, str.length)
}

