from collections import defaultdict
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())

dic = defaultdict(list)
for i, s in enumerate(S):
    dic[s].append(i)

Q = int(input())
for _ in [0]*Q:
    t, *q = input().split()
    if t == '1':
        i, c = q
        i = int(i)-1

        s = S[i]
        if s == c:
            continue
        S[i] = c
        dic[s].pop(bisect_left(dic[s], i))
        insort_left(dic[c], i)

    else:
        l, r = map(int, q)
        l -= 1
        r -= 1
        cnt = 0
        for L in dic.values():
            i = bisect_left(L, l)
            if i != len(L) and L[i] <= r:
                cnt += 1
        print(cnt) from collections import defaultdict from bisect import bisect_left, insort_left import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N = int(input()) N int(input()) int input() input S = list(input()) S list(input()) list input() input dic = defaultdict(list) dic defaultdict(list) defaultdict list for i, s in enumerate(S):
    dic[s].append(i) i s enumerate(S) enumerate S dic[s].append(i) [s].append [s] dic s append i Q = int(input()) Q int(input()) int input() input for _ in [0]*Q:
    t, *q = input().split()
    if t == '1':
        i, c = q
        i = int(i)-1

        s = S[i]
        if s == c:
            continue
        S[i] = c
        dic[s].pop(bisect_left(dic[s], i))
        insort_left(dic[c], i)

    else:
        l, r = map(int, q)
        l -= 1
        r -= 1
        cnt = 0
        for L in dic.values():
            i = bisect_left(L, l)
            if i != len(L) and L[i] <= r:
                cnt += 1
        print(cnt) _ [0]*Q [0] 0 Q t, *q = input().split() t input().split() ().split () input split *q q if t == '1':
        i, c = q
        i = int(i)-1

        s = S[i]
        if s == c:
            continue
        S[i] = c
        dic[s].pop(bisect_left(dic[s], i))
        insort_left(dic[c], i)

    else:
        l, r = map(int, q)
        l -= 1
        r -= 1
        cnt = 0
        for L in dic.values():
            i = bisect_left(L, l)
            if i != len(L) and L[i] <= r:
                cnt += 1
        print(cnt) t == '1' t '1' i, c = q i q c i = int(i)-1 i int(i)-1 int(i) int i 1 s = S[i] s S[i] S i if s == c:
            continue
         s == c s c continue S[i] = c S[i] S i c dic[s].pop(bisect_left(dic[s], i)) [s].pop [s] dic s pop bisect_left(dic[s], i) bisect_left dic[s] dic s i insort_left(dic[c], i) insort_left dic[c] dic c i l, r = map(int, q) l map(int, q) map int q r l -= 1 l 1 r -= 1 r 1 cnt = 0 cnt 0 for L in dic.values():
            i = bisect_left(L, l)
            if i != len(L) and L[i] <= r:
                cnt += 1
         L dic.values() dic.values dic values i = bisect_left(L, l) i bisect_left(L, l) bisect_left L l if i != len(L) and L[i] <= r:
                cnt += 1
         i != len(L) and L[i] <= r i != len(L) i len(L) len L L[i] <= r L[i] L i r cnt += 1 cnt 1 print(cnt) print cnt r -= 1 1 r cnt += 1 1 cnt c = q q c l -= 1 1 l cnt = 0 0 cnt dic = defaultdict(list) defaultdict(list) dic r = map(int, q) map(int, q) r i = bisect_left(L, l) bisect_left(L, l) i l, r = map(int, q) map(int, q) l N = int(input()) int(input()) N t, *q = input().split() input().split() t i = int(i)-1 int(i)-1 i S = list(input()) list(input()) S input = sys.stdin.readline sys.stdin.readline input i, c = q q i s = S[i] S[i] s Q = int(input()) int(input()) Q
from collections import defaultdict
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())

dic = defaultdict(list)
for i, s in enumerate(S):
    dic[s].append(i)

Q = int(input())
for _ in [0]*Q:
    t, *q = input().split()
    if t == '1':
        i, c = q
        i = int(i)-1

        s = S[i]
        if s == c:
            continue
        S[i] = c
        dic[s].pop(bisect_left(dic[s], i))
        insort_left(dic[c], i)

    else:
        l, r = map(int, q)
        l -= 1
        r -= 1
        cnt = 0
        for L in dic.values():
            i = bisect_left(L, l)
            if i != len(L) and L[i] <= r:
                cnt += 1
        print(cnt)
