import sys
import bisect

N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())
Q = int(sys.stdin.readline().rstrip())

idx = {chr(ord("a") + i): [] for i in range(26)}

for i, s in enumerate(S):
    idx[s].append(i + 1)

for _ in range(Q):
    t, i, c = sys.stdin.readline().rstrip().split()
    i = int(i)
    if t == "1":
        if S[i - 1] != c:
            idx[S[i - 1]].remove(i)
            bisect.insort(idx[c], i)
            S[i - 1] = c
    else:
        c = int(c)
        ans = 0
        for a, id in idx.items():
            x = bisect.bisect_left(id, i)
            y = bisect.bisect_right(id, c)
            if y - x:
                ans += 1
        print(ans) import sys sys import bisect bisect N = int(sys.stdin.readline().rstrip()) N int(sys.stdin.readline().rstrip()) int sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip S = list(sys.stdin.readline().rstrip()) S list(sys.stdin.readline().rstrip()) list sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip Q = int(sys.stdin.readline().rstrip()) Q int(sys.stdin.readline().rstrip()) int sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip 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 [] idx = {chr(ord("a") + i): [] for i in range(26)} idx {chr(ord("a") + i): [] for i in range(26)} for i, s in enumerate(S):
    idx[s].append(i + 1) i s enumerate(S) enumerate S idx[s].append(i + 1) [s].append [s] idx s append i + 1 i 1 for _ in range(Q):
    t, i, c = sys.stdin.readline().rstrip().split()
    i = int(i)
    if t == "1":
        if S[i - 1] != c:
            idx[S[i - 1]].remove(i)
            bisect.insort(idx[c], i)
            S[i - 1] = c
    else:
        c = int(c)
        ans = 0
        for a, id in idx.items():
            x = bisect.bisect_left(id, i)
            y = bisect.bisect_right(id, c)
            if y - x:
                ans += 1
        print(ans) _ range(Q) range Q t, i, c = sys.stdin.readline().rstrip().split() t sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip split i c i = int(i) i int(i) int i if t == "1":
        if S[i - 1] != c:
            idx[S[i - 1]].remove(i)
            bisect.insort(idx[c], i)
            S[i - 1] = c
    else:
        c = int(c)
        ans = 0
        for a, id in idx.items():
            x = bisect.bisect_left(id, i)
            y = bisect.bisect_right(id, c)
            if y - x:
                ans += 1
        print(ans) t == "1" t "1" if S[i - 1] != c:
            idx[S[i - 1]].remove(i)
            bisect.insort(idx[c], i)
            S[i - 1] = c
     S[i - 1] != c S[i - 1] S i - 1 i 1 c idx[S[i - 1]].remove(i) [S[i - 1]].remove [S[i - 1]] idx S[i - 1] S i - 1 i 1 remove i bisect.insort(idx[c], i) bisect.insort bisect insort idx[c] idx c i S[i - 1] = c S[i - 1] S i - 1 i 1 c c = int(c) c int(c) int c ans = 0 ans 0 for a, id in idx.items():
            x = bisect.bisect_left(id, i)
            y = bisect.bisect_right(id, c)
            if y - x:
                ans += 1
         a id idx.items() idx.items idx items x = bisect.bisect_left(id, i) x bisect.bisect_left(id, i) bisect.bisect_left bisect bisect_left id i y = bisect.bisect_right(id, c) y bisect.bisect_right(id, c) bisect.bisect_right bisect bisect_right id c if y - x:
                ans += 1
         y - x y x ans += 1 ans 1 print(ans) print ans S = list(sys.stdin.readline().rstrip()) list(sys.stdin.readline().rstrip()) S t, i, c = sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split() t i = int(i) int(i) i idx = {chr(ord("a") + i): [] for i in range(26)} {chr(ord("a") + i): [] for i in range(26)} idx ans = 0 0 ans Q = int(sys.stdin.readline().rstrip()) int(sys.stdin.readline().rstrip()) Q c = sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split() c x = bisect.bisect_left(id, i) bisect.bisect_left(id, i) x N = int(sys.stdin.readline().rstrip()) int(sys.stdin.readline().rstrip()) N c = int(c) int(c) c i, c = sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split() i y = bisect.bisect_right(id, c) bisect.bisect_right(id, c) y ans += 1 1 ans
import sys
import bisect

N = int(sys.stdin.readline().rstrip())
S = list(sys.stdin.readline().rstrip())
Q = int(sys.stdin.readline().rstrip())

idx = {chr(ord("a") + i): [] for i in range(26)}

for i, s in enumerate(S):
    idx[s].append(i + 1)

for _ in range(Q):
    t, i, c = sys.stdin.readline().rstrip().split()
    i = int(i)
    if t == "1":
        if S[i - 1] != c:
            idx[S[i - 1]].remove(i)
            bisect.insort(idx[c], i)
            S[i - 1] = c
    else:
        c = int(c)
        ans = 0
        for a, id in idx.items():
            x = bisect.bisect_left(id, i)
            y = bisect.bisect_right(id, c)
            if y - x:
                ans += 1
        print(ans)