import bisect

n = int(input())
s = list(input())
q = int(input())

alphabet = [chr(ord('a') + i) for i in range(26)]

d = {alphabet[i]: [] for i in range(26)}
for i, a in enumerate(s):
    d[a].append(i)

ans = []
for i in range(q):
    query = input().split()

    if query[0] == '1':
        idx, c = int(query[1]) - 1, query[2]
        if s[idx] == c:
            continue
        d[s[idx]].remove(idx)
        bisect.insort_left(d[c], idx)
        s[idx] = c
    else:
        l, r = int(query[1]) - 1, int(query[2]) - 1
        res = 0
        for c in alphabet:
            if bisect.bisect_right(d[c], r) > bisect.bisect_left(d[c], l):
                res += 1
        ans.append(res)

for i in ans:
    print(i) import bisect bisect 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 chr(ord('a') + i) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) chr(ord('a') + i) chr ord('a') + i ord('a') ord 'a' i alphabet = [chr(ord('a') + i) for i in range(26)] alphabet [chr(ord('a') + i) for i in range(26)] alphabet[i]: [] for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) alphabet[i] alphabet i [] d = {alphabet[i]: [] for i in range(26)} d {alphabet[i]: [] for i in range(26)} for i, a in enumerate(s):
    d[a].append(i) i a enumerate(s) enumerate s d[a].append(i) [a].append [a] d a append i ans = [] ans [] for i in range(q):
    query = input().split()

    if query[0] == '1':
        idx, c = int(query[1]) - 1, query[2]
        if s[idx] == c:
            continue
        d[s[idx]].remove(idx)
        bisect.insort_left(d[c], idx)
        s[idx] = c
    else:
        l, r = int(query[1]) - 1, int(query[2]) - 1
        res = 0
        for c in alphabet:
            if bisect.bisect_right(d[c], r) > bisect.bisect_left(d[c], l):
                res += 1
        ans.append(res) i range(q) range q query = input().split() query input().split() ().split () input split if query[0] == '1':
        idx, c = int(query[1]) - 1, query[2]
        if s[idx] == c:
            continue
        d[s[idx]].remove(idx)
        bisect.insort_left(d[c], idx)
        s[idx] = c
    else:
        l, r = int(query[1]) - 1, int(query[2]) - 1
        res = 0
        for c in alphabet:
            if bisect.bisect_right(d[c], r) > bisect.bisect_left(d[c], l):
                res += 1
        ans.append(res) query[0] == '1' query[0] query 0 '1' idx, c = int(query[1]) - 1, query[2] idx int(query[1]) - 1 int(query[1]) int query[1] query 1 1 c query[2] query 2 if s[idx] == c:
            continue
         s[idx] == c s[idx] s idx c continue d[s[idx]].remove(idx) [s[idx]].remove [s[idx]] d s[idx] s idx remove idx bisect.insort_left(d[c], idx) bisect.insort_left bisect insort_left d[c] d c idx s[idx] = c s[idx] s idx c l, r = int(query[1]) - 1, int(query[2]) - 1 l int(query[1]) - 1 int(query[1]) int query[1] query 1 1 r int(query[2]) - 1 int(query[2]) int query[2] query 2 1 res = 0 res 0 for c in alphabet:
            if bisect.bisect_right(d[c], r) > bisect.bisect_left(d[c], l):
                res += 1
         c alphabet if bisect.bisect_right(d[c], r) > bisect.bisect_left(d[c], l):
                res += 1
         bisect.bisect_right(d[c], r) > bisect.bisect_left(d[c], l) bisect.bisect_right(d[c], r) bisect.bisect_right bisect bisect_right d[c] d c r bisect.bisect_left(d[c], l) bisect.bisect_left bisect bisect_left d[c] d c l res += 1 res 1 ans.append(res) ans.append ans append res for i in ans:
    print(i) i ans print(i) print i d = {alphabet[i]: [] for i in range(26)} {alphabet[i]: [] for i in range(26)} d alphabet = [chr(ord('a') + i) for i in range(26)] [chr(ord('a') + i) for i in range(26)] alphabet l, r = int(query[1]) - 1, int(query[2]) - 1 int(query[1]) - 1 l s = list(input()) list(input()) s res += 1 1 res res = 0 0 res r = int(query[1]) - 1, int(query[2]) - 1 int(query[2]) - 1 r n = int(input()) int(input()) n q = int(input()) int(input()) q c = int(query[1]) - 1, query[2] query[2] c ans = [] [] ans query = input().split() input().split() query idx, c = int(query[1]) - 1, query[2] int(query[1]) - 1 idx
import bisect

n = int(input())
s = list(input())
q = int(input())

alphabet = [chr(ord('a') + i) for i in range(26)]

d = {alphabet[i]: [] for i in range(26)}
for i, a in enumerate(s):
    d[a].append(i)

ans = []
for i in range(q):
    query = input().split()

    if query[0] == '1':
        idx, c = int(query[1]) - 1, query[2]
        if s[idx] == c:
            continue
        d[s[idx]].remove(idx)
        bisect.insort_left(d[c], idx)
        s[idx] = c
    else:
        l, r = int(query[1]) - 1, int(query[2]) - 1
        res = 0
        for c in alphabet:
            if bisect.bisect_right(d[c], r) > bisect.bisect_left(d[c], l):
                res += 1
        ans.append(res)

for i in ans:
    print(i)