from collections import defaultdict
from bisect import bisect, insort, bisect_left
n = int(input())
s = list(input())
q = int(input())
d = defaultdict(list)
for i in range(n):
    d[s[i]] += [i]
for _ in range(q):
    t, i, c = input().split()
    t, i = int(t), int(i) - 1
    if t == 1:
        if s[i] == c:
            continue
        d[s[i]].pop(bisect(d[s[i]], i) - 1)
        s[i] = c
        insort(d[c], i)
    else:
        res = 0
        c = int(c) - 1
        for j in d.values():
            if bisect(j, c) - bisect_left(j, i):
                res += 1
        print(res) from collections import defaultdict from bisect import bisect, insort, bisect_left n = int(input()) n int(input()) int input() input s = list(input()) s list(input()) list input() input q = int(input()) q int(input()) int input() input d = defaultdict(list) d defaultdict(list) defaultdict list for i in range(n):
    d[s[i]] += [i] i range(n) range n d[s[i]] += [i] d[s[i]] d s[i] s i [i] i for _ in range(q):
    t, i, c = input().split()
    t, i = int(t), int(i) - 1
    if t == 1:
        if s[i] == c:
            continue
        d[s[i]].pop(bisect(d[s[i]], i) - 1)
        s[i] = c
        insort(d[c], i)
    else:
        res = 0
        c = int(c) - 1
        for j in d.values():
            if bisect(j, c) - bisect_left(j, i):
                res += 1
        print(res) _ range(q) range q t, i, c = input().split() t input().split() ().split () input split i c t, i = int(t), int(i) - 1 t int(t) int t i int(i) - 1 int(i) int i 1 if t == 1:
        if s[i] == c:
            continue
        d[s[i]].pop(bisect(d[s[i]], i) - 1)
        s[i] = c
        insort(d[c], i)
    else:
        res = 0
        c = int(c) - 1
        for j in d.values():
            if bisect(j, c) - bisect_left(j, i):
                res += 1
        print(res) t == 1 t 1 if s[i] == c:
            continue
         s[i] == c s[i] s i c continue d[s[i]].pop(bisect(d[s[i]], i) - 1) [s[i]].pop [s[i]] d s[i] s i pop bisect(d[s[i]], i) - 1 bisect(d[s[i]], i) bisect d[s[i]] d s[i] s i i 1 s[i] = c s[i] s i c insort(d[c], i) insort d[c] d c i res = 0 res 0 c = int(c) - 1 c int(c) - 1 int(c) int c 1 for j in d.values():
            if bisect(j, c) - bisect_left(j, i):
                res += 1
         j d.values() d.values d values if bisect(j, c) - bisect_left(j, i):
                res += 1
         bisect(j, c) - bisect_left(j, i) bisect(j, c) bisect j c bisect_left(j, i) bisect_left j i res += 1 res 1 print(res) print res t, i, c = input().split() input().split() t i, c = input().split() input().split() i c = input().split() input().split() c t, i = int(t), int(i) - 1 int(t) t d = defaultdict(list) defaultdict(list) d q = int(input()) int(input()) q i = int(t), int(i) - 1 int(i) - 1 i res = 0 0 res res += 1 1 res n = int(input()) int(input()) n s = list(input()) list(input()) s c = int(c) - 1 int(c) - 1 c
from collections import defaultdict
from bisect import bisect, insort, bisect_left
n = int(input())
s = list(input())
q = int(input())
d = defaultdict(list)
for i in range(n):
    d[s[i]] += [i]
for _ in range(q):
    t, i, c = input().split()
    t, i = int(t), int(i) - 1
    if t == 1:
        if s[i] == c:
            continue
        d[s[i]].pop(bisect(d[s[i]], i) - 1)
        s[i] = c
        insort(d[c], i)
    else:
        res = 0
        c = int(c) - 1
        for j in d.values():
            if bisect(j, c) - bisect_left(j, i):
                res += 1
        print(res)