//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 = "0" + readString()

    val bits = Array(26){BIT<Int>(N)}
    for (i in 1 until N+1) {
        bits[S[i] - 'a'].add1(i, 1)
    }

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

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


operator fun<T: Number> Number.plus(other: T): T {
    @Suppress("UNCHECKED_CAST")
    return when (other) {
        is Int -> (this.toInt() + other.toInt()) as T
        is Long -> (this.toLong() + other.toLong()) as T
        is Float -> (this.toFloat() + other.toFloat()) as T
        is Double -> (this.toDouble() + other.toDouble()) as T
        else -> throw IllegalAccessException("unsupported type ${other.javaClass}")
    }
}
operator fun<T: Number> Number.minus(other: T): T {
    @Suppress("UNCHECKED_CAST")
    return when (other) {
        is Int -> (this.toInt() - other.toInt()) as T
        is Long -> (this.toLong() - other.toLong()) as T
        is Float -> (this.toFloat() - other.toFloat()) as T
        is Double -> (this.toDouble() - other.toDouble()) as T
        else -> throw IllegalAccessException("unsupported type ${other.javaClass}")
    }
}
operator fun<T: Number> Number.unaryMinus(): T {
    @Suppress("UNCHECKED_CAST")
    return when (this) {
        is Int -> -this.toInt() as T
        is Long -> -this.toLong() as T
        is Float -> -this.toFloat() as T
        is Double -> -this.toDouble() as T
        else -> throw IllegalAccessException("unsupported type ${this.javaClass}")
    }
}
class BIT<T: Number>(val N: Int, val sg: ArrayList<T> = ArrayList()) {
    init {
        @Suppress("UNCHECKED_CAST")
        //sg.addAll(List(N+1){0 as T})
        for (i in 0 until N+1) {
            sg.add(0 as T)
        }
    }
    fun add1(I: Int, X: T) {
        var i = I
        while(i <= N) {
            sg[i] = sg[i] + X
            i += (i and (-i))
        }
    }
    fun sum1(I: Int): T {
        @Suppress("UNCHECKED_CAST")
        var res = 0 as T
        var i = I
        while (i > 0) {
            res = res + sg[i]
            i -= (i and (-i))
        }
        return res
    }
    fun sum(i: Int, j: Int): T {
        return sum1(j) - sum1(i-1)
    }
}

Measured memory_bytes: 177432