import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    var str = scanner.nextLine()
    val q = scanner.nextInt()
    (1..q).forEach {
        val command = scanner.next()
        str = when(command) {
            "print" -> {
                val a = scanner.nextInt()
                val b = scanner.nextInt()
                println(str.substring(a, b + 1))
                str
            }
            "reverse" -> {
                val a = scanner.nextInt()
                val b = scanner.nextInt()
                str.substring(0, a) + str.substring(a, b + 1).reversed() + str.substring(b + 1)
            }
            "replace" -> {
                val a = scanner.nextInt()
                val b = scanner.nextInt()
                val p = scanner.next()
                str.substring(0, a) + p + str.substring(b + 1)
            }
            else -> str
        }
    }
}
