# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub, or_

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)



def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree:
    def __init__(self, array, operator, identity_element):
        _len = len(array)
        self.__op = operator
        self.__size = 1 << (_len - 1).bit_length()
        self.__tree = [identity_element] * self.__size + \
            array + [identity_element] * (self.__size - _len)
        self.__ie = identity_element

        for i in range(self.__size - 1, 0, -1):
            self.__tree[i] = operator(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def update(self, i, v):
        i += self.__size
        self.__tree[i] = v
        while i:
            i //= 2
            self.__tree[i] = self.__op(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def query(self, l, r):
        l += self.__size
        r += self.__size
        ret = self.__ie
        while l < r:
            if l & 1:
                ret = self.__op(ret, self.__tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.__op(ret, self.__tree[r])
            l //= 2
            r //= 2
        return ret


@mt
def slv(N, S, Q):
    st = [SegmentTree([1 if ord(c) == ord('a')+ _ else 0 for c in S], add, 0) for _ in range(26)]
    S = [c for c in S]
    for q in Q:
        if q[0] == '1':
            i = int(q[1]) - 1
            c = S[i]
            st[ord(c)-ord('a')].update(i, 0)
            c = q[2]
            st[ord(c)-ord('a')].update(i, 1)
            S[i] = c
        if q[0] == '2':
            i = int(q[1]) - 1
            j = int(q[2]) - 1
            ans = 0
            for k in range(26):
                if st[k].query(i, j+1) > 0:
                    ans += 1
            print(ans)

# def slv(N, S, Q):
#     st = SegmentTree([1 << (ord(c) - ord('a')) for c in S], or_, 0)

#     for q in Q:
#         if q[0] == '1':
#             i = int(q[1]) - 1
#             c = q[2]
#             st.update(i, 1 << (ord(c) - ord('a')))
#         if q[0] == '2':
#             i = int(q[1]) - 1
#             j = int(q[2]) - 1
#             ans = 0
#             v = st.query(i, j+1)
#             for k in range(26):
#                 if (1 << k) & v:
#                     ans += 1
#             print(ans)


def main():
    N = read_int()
    S = read_str()
    Q = [read_str_n() for _ in range(read_int())]
    (slv(N, S, Q))

if __name__ == '__main__':
    main()


Measured memory_bytes: 402500