# test!!!!!!!!!!!

from bisect import bisect_left, bisect_right

N = int(input())

S = list(input())

Q = int(input())

# {"a":[], "b":[], ..., "z":[]}
dict = {chr(ord('a') + i): [] for i in range(26)}


for i in range(N):
    dict[S[i]].append(i)

ans = []

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1])-1, query[2]
        now = S[i]
        if now == x:
            continue
        dict[now].remove(i)
        next_i = bisect_left(dict[x], i)
        dict[x].insert(next_i, i)
        S[i] = x
    else:
        start, end = int(query[1])-1, int(query[2])-1
        tmp_cout = 0
        for alf_array in dict.values():
            if len(alf_array) == 0:
                continue
            ss = bisect_left(alf_array, start)
            gg = bisect_right(alf_array, end)
            if gg- ss > 0:
                tmp_cout += 1
        ans.append(tmp_cout)

for i in ans:
    print(i) 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 [] dict = {chr(ord('a') + i): [] for i in range(26)} dict {chr(ord('a') + i): [] for i in range(26)} for i in range(N):
    dict[S[i]].append(i) i range(N) range N dict[S[i]].append(i) [S[i]].append [S[i]] dict S[i] S i append i ans = [] ans [] for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1])-1, query[2]
        now = S[i]
        if now == x:
            continue
        dict[now].remove(i)
        next_i = bisect_left(dict[x], i)
        dict[x].insert(next_i, i)
        S[i] = x
    else:
        start, end = int(query[1])-1, int(query[2])-1
        tmp_cout = 0
        for alf_array in dict.values():
            if len(alf_array) == 0:
                continue
            ss = bisect_left(alf_array, start)
            gg = bisect_right(alf_array, end)
            if gg- ss > 0:
                tmp_cout += 1
        ans.append(tmp_cout) 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])-1, query[2]
        now = S[i]
        if now == x:
            continue
        dict[now].remove(i)
        next_i = bisect_left(dict[x], i)
        dict[x].insert(next_i, i)
        S[i] = x
    else:
        start, end = int(query[1])-1, int(query[2])-1
        tmp_cout = 0
        for alf_array in dict.values():
            if len(alf_array) == 0:
                continue
            ss = bisect_left(alf_array, start)
            gg = bisect_right(alf_array, end)
            if gg- ss > 0:
                tmp_cout += 1
        ans.append(tmp_cout) query[0] == '1' query[0] query 0 '1' i, x = int(query[1])-1, query[2] i int(query[1])-1 int(query[1]) int query[1] query 1 1 x query[2] query 2 now = S[i] now S[i] S i if now == x:
            continue
         now == x now x continue dict[now].remove(i) [now].remove [now] dict now remove i next_i = bisect_left(dict[x], i) next_i bisect_left(dict[x], i) bisect_left dict[x] dict x i dict[x].insert(next_i, i) [x].insert [x] dict x insert next_i i S[i] = x S[i] S i x start, end = int(query[1])-1, int(query[2])-1 start int(query[1])-1 int(query[1]) int query[1] query 1 1 end int(query[2])-1 int(query[2]) int query[2] query 2 1 tmp_cout = 0 tmp_cout 0 for alf_array in dict.values():
            if len(alf_array) == 0:
                continue
            ss = bisect_left(alf_array, start)
            gg = bisect_right(alf_array, end)
            if gg- ss > 0:
                tmp_cout += 1
         alf_array dict.values() dict.values dict values if len(alf_array) == 0:
                continue
             len(alf_array) == 0 len(alf_array) len alf_array 0 continue ss = bisect_left(alf_array, start) ss bisect_left(alf_array, start) bisect_left alf_array start gg = bisect_right(alf_array, end) gg bisect_right(alf_array, end) bisect_right alf_array end if gg- ss > 0:
                tmp_cout += 1
         gg- ss > 0 gg- ss gg ss 0 tmp_cout += 1 tmp_cout 1 ans.append(tmp_cout) ans.append ans append tmp_cout for i in ans:
    print(i) i ans print(i) print i i, x = int(query[1])-1, query[2] int(query[1])-1 i tmp_cout += 1 1 tmp_cout query = list(input().split()) list(input().split()) query gg = bisect_right(alf_array, end) bisect_right(alf_array, end) gg dict = {chr(ord('a') + i): [] for i in range(26)} {chr(ord('a') + i): [] for i in range(26)} dict start, end = int(query[1])-1, int(query[2])-1 int(query[1])-1 start N = int(input()) int(input()) N end = int(query[1])-1, int(query[2])-1 int(query[2])-1 end now = S[i] S[i] now x = int(query[1])-1, query[2] query[2] x S = list(input()) list(input()) S Q = int(input()) int(input()) Q ss = bisect_left(alf_array, start) bisect_left(alf_array, start) ss ans = [] [] ans next_i = bisect_left(dict[x], i) bisect_left(dict[x], i) next_i tmp_cout = 0 0 tmp_cout
# test!!!!!!!!!!!

from bisect import bisect_left, bisect_right

N = int(input())

S = list(input())

Q = int(input())

# {"a":[], "b":[], ..., "z":[]}
dict = {chr(ord('a') + i): [] for i in range(26)}


for i in range(N):
    dict[S[i]].append(i)

ans = []

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1])-1, query[2]
        now = S[i]
        if now == x:
            continue
        dict[now].remove(i)
        next_i = bisect_left(dict[x], i)
        dict[x].insert(next_i, i)
        S[i] = x
    else:
        start, end = int(query[1])-1, int(query[2])-1
        tmp_cout = 0
        for alf_array in dict.values():
            if len(alf_array) == 0:
                continue
            ss = bisect_left(alf_array, start)
            gg = bisect_right(alf_array, end)
            if gg- ss > 0:
                tmp_cout += 1
        ans.append(tmp_cout)

for i in ans:
    print(i)
