from bisect import bisect_left, bisect_right

N = int(input())
S = list(input())
Q = int(input())

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

for i, s in enumerate(S):
    D[s].append(i)

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1]), query[2]
        i -= 1
        s = S[i]
        if s == x:
            continue

        D[s].remove(i)
        next_i = bisect_left(D[x], i)
        D[x].insert(next_i, i)
        S[i] = x

    if query[0] == '2':
        l, r = int(query[1]), int(query[2])
        l, r = l - 1, r - 1
        ans = 0
        for i in range(26):
            s = chr(ord('a') + i)

            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)

            if ri - li > 0:
                ans += 1

        print(ans) from bisect import bisect_left, bisect_right 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 [] D = {chr(ord('a') + i): [] for i in range(26)} D {chr(ord('a') + i): [] for i in range(26)} for i, s in enumerate(S):
    D[s].append(i) i s enumerate(S) enumerate S D[s].append(i) [s].append [s] D s append i for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1]), query[2]
        i -= 1
        s = S[i]
        if s == x:
            continue

        D[s].remove(i)
        next_i = bisect_left(D[x], i)
        D[x].insert(next_i, i)
        S[i] = x

    if query[0] == '2':
        l, r = int(query[1]), int(query[2])
        l, r = l - 1, r - 1
        ans = 0
        for i in range(26):
            s = chr(ord('a') + i)

            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)

            if ri - li > 0:
                ans += 1

        print(ans) q range(Q) range Q query = list(input().split()) query list(input().split()) list input().split() ().split () input split if query[0] == '1':
        i, x = int(query[1]), query[2]
        i -= 1
        s = S[i]
        if s == x:
            continue

        D[s].remove(i)
        next_i = bisect_left(D[x], i)
        D[x].insert(next_i, i)
        S[i] = x

     query[0] == '1' query[0] query 0 '1' i, x = int(query[1]), query[2] i int(query[1]) int query[1] query 1 x query[2] query 2 i -= 1 i 1 s = S[i] s S[i] S i if s == x:
            continue

         s == x s x continue D[s].remove(i) [s].remove [s] D s remove i next_i = bisect_left(D[x], i) next_i bisect_left(D[x], i) bisect_left D[x] D x i D[x].insert(next_i, i) [x].insert [x] D x insert next_i i S[i] = x S[i] S i x if query[0] == '2':
        l, r = int(query[1]), int(query[2])
        l, r = l - 1, r - 1
        ans = 0
        for i in range(26):
            s = chr(ord('a') + i)

            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)

            if ri - li > 0:
                ans += 1

        print(ans) query[0] == '2' query[0] query 0 '2' l, r = int(query[1]), int(query[2]) l int(query[1]) int query[1] query 1 r int(query[2]) int query[2] query 2 l, r = l - 1, r - 1 l l - 1 l 1 r r - 1 r 1 ans = 0 ans 0 for i in range(26):
            s = chr(ord('a') + i)

            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)

            if ri - li > 0:
                ans += 1

         i range(26) range 26 s = chr(ord('a') + i) s chr(ord('a') + i) chr ord('a') + i ord('a') ord 'a' i li = bisect_left(D[s], l) li bisect_left(D[s], l) bisect_left D[s] D s l ri = bisect_right(D[s], r) ri bisect_right(D[s], r) bisect_right D[s] D s r if ri - li > 0:
                ans += 1

         ri - li > 0 ri - li ri li 0 ans += 1 ans 1 print(ans) print ans r = l - 1, r - 1 r - 1 r ans = 0 0 ans N = int(input()) int(input()) N l, r = int(query[1]), int(query[2]) int(query[1]) l s = chr(ord('a') + i) chr(ord('a') + i) s ans += 1 1 ans next_i = bisect_left(D[x], i) bisect_left(D[x], i) next_i S = list(input()) list(input()) S r = int(query[1]), int(query[2]) int(query[2]) r D = {chr(ord('a') + i): [] for i in range(26)} {chr(ord('a') + i): [] for i in range(26)} D li = bisect_left(D[s], l) bisect_left(D[s], l) li ri = bisect_right(D[s], r) bisect_right(D[s], r) ri i, x = int(query[1]), query[2] int(query[1]) i l, r = l - 1, r - 1 l - 1 l s = S[i] S[i] s x = int(query[1]), query[2] query[2] x query = list(input().split()) list(input().split()) query Q = int(input()) int(input()) Q i -= 1 1 i
from bisect import bisect_left, bisect_right

N = int(input())
S = list(input())
Q = int(input())

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

for i, s in enumerate(S):
    D[s].append(i)

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1]), query[2]
        i -= 1
        s = S[i]
        if s == x:
            continue

        D[s].remove(i)
        next_i = bisect_left(D[x], i)
        D[x].insert(next_i, i)
        S[i] = x

    if query[0] == '2':
        l, r = int(query[1]), int(query[2])
        l, r = l - 1, r - 1
        ans = 0
        for i in range(26):
            s = chr(ord('a') + i)

            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)

            if ri - li > 0:
                ans += 1

        print(ans)