fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val S = readLine()!!.toCharArray()
    val Q = readLine()!!.toInt()

    val f = Array(26) { Fenwick(N + 1) }

    for (i in S.indices) {
        val c = S[i] - 'a'
        f[c].add(i + 1, 1)
    }

    for (t in 1..Q) {
        val (a, b, c) = readLine()!!.split(" ")

        if (a == "1") {
            val i = b.toInt()

            if (S[i - 1] != c[0]) {
                f[S[i - 1] - 'a'].add(i, -1)
                f[c[0] - 'a'].add(i, 1)
                S[i - 1] = c[0]
            }
        } else {
            val l = b.toInt()
            val r = c.toInt()
            var res = 0
            for (i in 0 until 26) {
                if (f[i].get(r) - f[i].get(l - 1) > 0) {
                    ++res
                }
            }

            println(res)
        }
    }
}

class Fenwick(val n: Int) {
    val bit = IntArray(n + 1) { 0 }

    fun add(i_: Int, v: Int) {
        val n = bit.size
        var i = i_ + 1
        while(i < n) {
            bit[i] += v
            i += i and -i
        }
    }

    fun get(i_: Int): Int {
        var res = 0
        var i = i_ + 1
        while(i > 0) {
            res += bit[i]
            i -= i and -i
        }

        return res
    }
}
