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

from bisect import bisect_left, bisect_right

N = int(input())

S = list(input())

Q = int(input())

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

for key,val in enumerate(S):
    memo[val].append(key)

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

from bisect import bisect_left, bisect_right

N = int(input())

S = list(input())

Q = int(input())

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

for key,val in enumerate(S):
    memo[val].append(key)

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
        memo[now].remove(i)
        next_i = bisect_left(memo[x], i)
        memo[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 memo.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
        print(tmp_cout)
