from bisect import bisect_left, insort_left
N = int(input())
S = [c for c in input()]
Q = int(input())
d = {i: [] for i in range(26)}
for i, c in enumerate(S):
    d[ord(c) - ord("a")].append(i)

# print(d)
for _ in range(Q):
    q = input().split()
    if int(q[0]) == 1:
        iq, cq = int(q[1]), q[2]
        iq -= 1
        if S[iq] == cq:
            continue
        else:
            idx = bisect_left(d[ord(S[iq]) - ord("a")], iq)
            d[ord(S[iq]) - ord("a")].pop(idx)
            S[iq] = cq
            insort_left(d[ord(cq) - ord("a")], iq)
    else:
        l, r = int(q[1]), int(q[2])
        l -= 1
        ans = 0
        for i in range(26):
            idx = bisect_left(d[i], l)
            if d[i] and l <= d[i][-1] and d[i][idx] < r:
                ans += 1
        print(ans)
 from bisect import bisect_left, insort_left N = int(input()) N int(input()) int input() input c for c in input() for c in input() c input() input for c in input() c S = [c for c in input()] S [c for c in input()] Q = int(input()) Q int(input()) int input() input i: [] for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) i [] d = {i: [] for i in range(26)} d {i: [] for i in range(26)} for i, c in enumerate(S):
    d[ord(c) - ord("a")].append(i)

# print(d) i c enumerate(S) enumerate S d[ord(c) - ord("a")].append(i) [ord(c) - ord("a")].append [ord(c) - ord("a")] d ord(c) - ord("a") ord(c) ord c ord("a") ord "a" append i for _ in range(Q):
    q = input().split()
    if int(q[0]) == 1:
        iq, cq = int(q[1]), q[2]
        iq -= 1
        if S[iq] == cq:
            continue
        else:
            idx = bisect_left(d[ord(S[iq]) - ord("a")], iq)
            d[ord(S[iq]) - ord("a")].pop(idx)
            S[iq] = cq
            insort_left(d[ord(cq) - ord("a")], iq)
    else:
        l, r = int(q[1]), int(q[2])
        l -= 1
        ans = 0
        for i in range(26):
            idx = bisect_left(d[i], l)
            if d[i] and l <= d[i][-1] and d[i][idx] < r:
                ans += 1
        print(ans) _ range(Q) range Q q = input().split() q input().split() ().split () input split if int(q[0]) == 1:
        iq, cq = int(q[1]), q[2]
        iq -= 1
        if S[iq] == cq:
            continue
        else:
            idx = bisect_left(d[ord(S[iq]) - ord("a")], iq)
            d[ord(S[iq]) - ord("a")].pop(idx)
            S[iq] = cq
            insort_left(d[ord(cq) - ord("a")], iq)
    else:
        l, r = int(q[1]), int(q[2])
        l -= 1
        ans = 0
        for i in range(26):
            idx = bisect_left(d[i], l)
            if d[i] and l <= d[i][-1] and d[i][idx] < r:
                ans += 1
        print(ans) int(q[0]) == 1 int(q[0]) int q[0] q 0 1 iq, cq = int(q[1]), q[2] iq int(q[1]) int q[1] q 1 cq q[2] q 2 iq -= 1 iq 1 if S[iq] == cq:
            continue
        else:
            idx = bisect_left(d[ord(S[iq]) - ord("a")], iq)
            d[ord(S[iq]) - ord("a")].pop(idx)
            S[iq] = cq
            insort_left(d[ord(cq) - ord("a")], iq)
     S[iq] == cq S[iq] S iq cq continue idx = bisect_left(d[ord(S[iq]) - ord("a")], iq) idx bisect_left(d[ord(S[iq]) - ord("a")], iq) bisect_left d[ord(S[iq]) - ord("a")] d ord(S[iq]) - ord("a") ord(S[iq]) ord S[iq] S iq ord("a") ord "a" iq d[ord(S[iq]) - ord("a")].pop(idx) [ord(S[iq]) - ord("a")].pop [ord(S[iq]) - ord("a")] d ord(S[iq]) - ord("a") ord(S[iq]) ord S[iq] S iq ord("a") ord "a" pop idx S[iq] = cq S[iq] S iq cq insort_left(d[ord(cq) - ord("a")], iq) insort_left d[ord(cq) - ord("a")] d ord(cq) - ord("a") ord(cq) ord cq ord("a") ord "a" iq l, r = int(q[1]), int(q[2]) l int(q[1]) int q[1] q 1 r int(q[2]) int q[2] q 2 l -= 1 l 1 ans = 0 ans 0 for i in range(26):
            idx = bisect_left(d[i], l)
            if d[i] and l <= d[i][-1] and d[i][idx] < r:
                ans += 1
         i range(26) range 26 idx = bisect_left(d[i], l) idx bisect_left(d[i], l) bisect_left d[i] d i l if d[i] and l <= d[i][-1] and d[i][idx] < r:
                ans += 1
         d[i] and l <= d[i][-1] and d[i][idx] < r d[i] and l <= d[i][-1] d[i] d i l <= d[i][-1] l d[i][-1] [i] d i -1 d[i][idx] < r d[i][idx] [i] d i idx r ans += 1 ans 1 print(ans) print ans ans += 1 1 ans iq, cq = int(q[1]), q[2] int(q[1]) iq q = input().split() input().split() q r = int(q[1]), int(q[2]) int(q[2]) r d = {i: [] for i in range(26)} {i: [] for i in range(26)} d cq = int(q[1]), q[2] q[2] cq Q = int(input()) int(input()) Q S = [c for c in input()] [c for c in input()] S iq -= 1 1 iq l, r = int(q[1]), int(q[2]) int(q[1]) l ans = 0 0 ans idx = bisect_left(d[ord(S[iq]) - ord("a")], iq) bisect_left(d[ord(S[iq]) - ord("a")], iq) idx N = int(input()) int(input()) N l -= 1 1 l idx = bisect_left(d[i], l) bisect_left(d[i], l) idx
from bisect import bisect_left, insort_left
N = int(input())
S = [c for c in input()]
Q = int(input())
d = {i: [] for i in range(26)}
for i, c in enumerate(S):
    d[ord(c) - ord("a")].append(i)

# print(d)
for _ in range(Q):
    q = input().split()
    if int(q[0]) == 1:
        iq, cq = int(q[1]), q[2]
        iq -= 1
        if S[iq] == cq:
            continue
        else:
            idx = bisect_left(d[ord(S[iq]) - ord("a")], iq)
            d[ord(S[iq]) - ord("a")].pop(idx)
            S[iq] = cq
            insort_left(d[ord(cq) - ord("a")], iq)
    else:
        l, r = int(q[1]), int(q[2])
        l -= 1
        ans = 0
        for i in range(26):
            idx = bisect_left(d[i], l)
            if d[i] and l <= d[i][-1] and d[i][idx] < r:
                ans += 1
        print(ans)

