import java.util.*

var n = -1
val bit = Array(26) {Array(500002) {0}}

// 1-indexed
fun sum(alpha:Int, i: Int): Int{
    var res = 0
    var j = i
    while (j > 0) {
        res += bit[alpha][j];
        j -= j and (-j)
    }
    return res
}

fun sum(alpha: Int, i: Int, j: Int): Int {
    return sum(alpha, j) - sum(alpha, i - 1)
}

fun add(alpha: Int, i: Int, value: Int){
    var j = i
    while(j <= n){
        bit[alpha][j] += value
        j += j and (-j)
    }
}

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    n = sc.nextInt()
    val s = sc.next().toCharArray()
    s.forEachIndexed { index, c -> add(c - 'a', index + 1, 1) }
    val q = sc.nextInt()
    repeat(q) {
        val op = sc.nextInt()
        if (op == 1) {
            val i = sc.nextInt()
            val from = s[i - 1] - 'a'
            val to = sc.next()[0] - 'a'
            s[i - 1] = 'a' + to
            add(from, i, -1)
            add(to, i, 1)
        } else {
            val l = sc.nextInt()
            val r = sc.nextInt()
            println((0 until 26).map { if(sum(it, l, r) > 0) 1 else 0 }.sum())
        }
    }
}