//package Qe
import java.util.*
import java.math.*
import java.lang.Math.*

private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = {readLine()!!.toInt()}
private val readLong: ()->Long = {readLine()!!.toLong()}
private val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
private val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
private val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
private val MOD = 1e9.toLong()+7
private val INF = Int.MAX_VALUE/2
private val LINF = Long.MAX_VALUE/2


fun main(args: Array<String>) {
    val N = readInt()
    val S = readString()

    val bits = Array(26){LongBIT(N)}
    for (i in 0 until N) {
        bits[S[i] - 'a'].add(i, 1)
    }

    val Q = readInt()
    var ca = S.toCharArray()
    for (q in 0 until Q) {
        val (type, a, b) = readString().split(" ")

        when (type) {
            "1" -> {
                val I = a.toInt()-1
                val C = b[0]
                if (ca[I] != C) {
                    bits[ca[I] - 'a'].add(I, -1)
                    bits[C - 'a'].add(I, 1)
                    ca[I] = C
                }
            }
            "2" -> {
                val L = a.toInt()-1; val R = b.toInt()
                var ans = 0
                for (bit in bits) {
                    if (bit.sum(L, R) > 0) ans++
                }
                println(ans)
            }
        }
    }
}


class LongBIT(val N: Int) {
    var sg = LongArray(0)
    init {
        sg = LongArray(N+1){0L}
    }
    private fun add1(I: Int, X: Long) {
        var i = I
        while(i <= N) {
            sg[i] += X
            i += i and -i
        }
    }
    private fun sum1(I: Int): Long {
        var res = 0L
        var i = I
        while (i > 0) {
            res += sg[i]
            i -= i and -i
        }
        return res
    }
    private fun sum1(i: Int, j: Int): Long {
        if (i>j) return 0L
        return sum1(j) - sum1(i-1)
    }
    fun add(I: Int, X: Long) {
        var i = I+1
        while(i <= N) {
            sg[i] += X
            i += i and -i
        }
    }
    fun sum(i: Int): Long {
        return sum1(i)
    }
    fun sum(i: Int, j: Int): Long {
        return sum1(j) - sum1(i)
    }
    operator fun get(i: Int): Long {
        return sum(i, i+1)
    }
}
