import java.util.TreeSet
fun main(args: Array<String>) {
    val N = nextInt()
    val S = next().toCharArray()
    val M = Array(26) { TreeSet<Int>() }
    S.forEachIndexed { index, char -> M[char - 'a'].add(index) }
    val Q = nextInt()
    repeat(Q) {
        val q = listOfString()
        val k = q[0].toInt()
        if (k == 1) {
            val i = q[1].toInt() - 1
            val c = q[2][0]
            M[S[i] - 'a'].remove(i)
            M[c - 'a'].add(i)
            S[i] = c
        } else {
            val l = q[1].toInt() - 1
            val r = q[2].toInt()
            var ans = M.count { (it.ceiling(l) ?: N) < r }
            println(ans)
        }
    }

}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
