class IntSegmentTree(n: Int) {
    private var size = 1

    init {
        while (size < n) {
            size *= 2
        }
    }

    private val segTree = IntArray(size * 2 - 1) { 0 }

    fun update(x: Int, value: Int) {
        var tmp = x + size - 1

        segTree[tmp] = value
        while (tmp > 0) {
            tmp = (tmp - 1) / 2
            segTree[tmp] = segTree[2 * tmp + 1] + segTree[2 * tmp + 2]
        }
    }

    fun getSum(a: Int, b: Int, k: Int = 0, l: Int = 0, r: Int = size): Int {
        if (r <= a || b <= l) {
            return 0
        }
        if (a <= l && r <= b) {
            return segTree[k]
        }

        val vl = getSum(a, b, 2 * k + 1, l, (l + r) / 2)
        val vr = getSum(a, b, 2 * k + 2, (l + r) / 2, r)

        return vl + vr
    }
}

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

    val segTree = Array(26) { IntSegmentTree(N) }

    for (i in 0 until N) {
        segTree[S[i] - 'a'].update(i, 1)
    }

    for (i in 0 until Q) {
        val (q, p1, p2) = readInputLine().split(" ")
        if (q == "1") {
            val index = p1.toInt() - 1
            val ch = p2.first()

            segTree[S[index] - 'a'].update(index, 0)
            segTree[ch - 'a'].update(index, 1)
            S[index] = ch
        } else {
            val l = p1.toInt() - 1
            val r = p2.toInt() - 1

            var cnt = 0
            for (k in 0 until 26) {
                if (segTree[k].getSum(l, r + 1) != 0) {
                    cnt++
                }
            }

            println(cnt)
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}
