//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){BIT<Int>(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)
            }
        }
    }
}


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")
        for (i in 0 until N+1) {
            sg.add(0 as T)
        }
    }
    private fun add1(I: Int, X: T) {
        var i = I
        while(i <= N) {
            sg[i] = sg[i] + X
            i += i and -i
        }
    }
    private fun sum1(I: Int): T {
        @Suppress("UNCHECKED_CAST")
        var res:T = 0 as T
        var i = I
        while (i > 0) {
            res += sg[i]
            i -= i and -i
        }
        return res
    }
    private fun sum1(i: Int, j: Int): T {
        @Suppress("UNCHECKED_CAST")
        if (i>j) return 0 as T
        return sum1(j) - sum1(i-1)
    }
    fun add(I: Int, X: T) {
        var i = I+1
        while(i <= N) {
            sg[i] = sg[i] + X
            i += i and -i
        }
    }
    fun sum(i: Int): T {
        return sum1(i)
    }
    fun sum(i: Int, j: Int): T {
        return sum1(j) - sum1(i)
    }
    operator fun get(i: Int): T {
        return sum(i, i+1)
    }
}


Measured memory_bytes: 172256