object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val str = sc.nextLine()
  val q = sc.nextLine()
  val cmds = List.fill(q.toInt)(sc.nextLine())
  val processor = makeProcessor
  cmds.foreach(cmdStr => processor(analysisCmdStr(cmdStr)))

  def makeProcessor: (List[String]) => Unit = {
    var result = str
    (cmd: List[String]) =>
      cmd.head match {
        case "replace" => result = result.pReplace(cmd(1).toInt, cmd(2).toInt, cmd(3))
        case "reverse" => result = result.pReverse(cmd(1).toInt, cmd(2).toInt)
        case "print" => result.pPrint(cmd(1).toInt, cmd(2).toInt)
        case _ =>
      }
  }

  def analysisCmdStr(line: String): List[String] = line.split(" ").toList

  implicit class StringExtends(val s: String) extends AnyVal {
    def pReplace(a: Int, b: Int, p: String): String = s.patch(a, p, b - a + 1)

    def pReverse(a: Int, b: Int): String = s.patch(a, s.substring(a, b + 1).reverse, b - a + 1)

    def pPrint(a: Int, b: Int): Unit = println(s.substring(a, b + 1))
  }