object Main extends App {
  val sc = new java.util.Scanner (Console.in)

  def print(s: String, a: Int, b: Int): Unit =
    println(s.substring(a, b+1))
  def reverse(s: String, a: Int, b: Int): String =
    s.take(a) + s.substring(a, b+1).reverse + s.drop(b+1)
  def replace(s: String, a: Int, b: Int, p: String): String =
    s.take(a) + p + s.drop(b+1)

  def next() = sc.next
  def nextInt() = sc.next.toInt

  var str = next
  var n = nextInt

  while (n > 0) {
    val cmd = next
    if (cmd == "print")
      print(str, nextInt, nextInt)
    else if (cmd == "reverse")
      str = reverse(str, nextInt, nextInt)
    else
      str = replace(str, nextInt, nextInt, next)

    n -= 1
  }
}

