object Main {
  def main(args: Array[String]): Unit = {
    val str = io.StdIn.readLine().toArray
    val q = io.StdIn.readInt()
    for (_ <- 0 until q) {
      val line = io.StdIn.readLine().split(" ")
      Operation(line).run(str)
    }
  }

  sealed trait Operation {
    def a: Int
    def b: Int
    def run(str: Array[Char]): Unit = this match {
      case Replace(a, b, r) =>
        r.zip(a to b).foreach { case (c, i) => str(i) = c }
      case Reverse(a, b) =>
        (0 to (b - a) / 2).foreach { i =>
          val buf = str(b - i)
          str(b - i) = str(a + i)
          str(a + i) = buf
        }
      case Print(a, b) =>
        println(str.subSequence(a, b + 1))
    }
  }
  object Operation {
    def apply(values: Array[String]): Operation = values match {
      case Array("replace", a, b, r) => Replace(a.toInt, b.toInt, r)
      case Array("reverse", a, b) => Reverse(a.toInt, b.toInt)
      case _ => Print(values(1).toInt, values(2).toInt)
    }
  }

  case class Replace(a: Int, b: Int, replacement: String) extends Operation
  case class Reverse(a: Int, b: Int) extends Operation
  case class Print(a: Int, b: Int) extends Operation
}