fun main(args: Array<String>) {
    var inputString = readLine()!!
    val commandNum = readLine()!!.toInt()
    (0 until commandNum).forEach {
        val variables = readLine()!!.split(" ")
        val command = variables[0]
        val startIdx = variables[1].toInt()
        val endIdx = variables[2].toInt()
        when (command) {
            "replace" -> {inputString = inputString.replaceRange(startIdx, endIdx + 1, variables[3])}
            "reverse" -> {inputString = inputString.replaceRange(
                    startIdx, endIdx + 1, inputString.substring(startIdx, endIdx + 1).reversed())
            }
            "print" -> println("${inputString.substring(startIdx, endIdx + 1)}")
        }
    }
}

