#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right


n = int(input())
s = list(input())
q = int(input())

al = 'abcdefghijklmnopqrstuvwxyz'
dicq = {i:[] for i in al}
for i, si in enumerate(s):
    dicq[si].append(i)

def q1(iq, cq):
    #print(iq,cq,s[iq],dicq[s[iq]],bisect_left(dicq[s[iq]], iq))
    dicq[s[iq]].pop(bisect_left(dicq[s[iq]], iq))   #更新前から削除
    s[iq] = cq
    dicq[cq].insert(bisect_left(dicq[cq], iq), iq)   #更新後に追加

def q2(l, r):
    ret = 0
    for ai in al:
        if len(dicq[ai])==0: continue
        li = bisect_left(dicq[ai], l)
        ri = bisect_right(dicq[ai], r)
        if li != ri:
            ret += 1
        elif li == len(dicq[ai]): continue
        elif dicq[ai][li] == l:
            ret += 1
    #    print(l,r,ai,dicq[ai],li,ri,ret)
    print(ret)

for i in range(q):
    fg, x, y = input().split()
    if fg == '1':
        q1(int(x)-1, y)
    else:
        q2(int(x)-1, int(y)-1) 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 al = 'abcdefghijklmnopqrstuvwxyz' al 'abcdefghijklmnopqrstuvwxyz' i:[] for i in al for i in al i al for i in al i [] dicq = {i:[] for i in al} dicq {i:[] for i in al} for i, si in enumerate(s):
    dicq[si].append(i) i si enumerate(s) enumerate s dicq[si].append(i) [si].append [si] dicq si append i def q1(iq, cq):
    #print(iq,cq,s[iq],dicq[s[iq]],bisect_left(dicq[s[iq]], iq))
    dicq[s[iq]].pop(bisect_left(dicq[s[iq]], iq))   #更新前から削除
    s[iq] = cq
    dicq[cq].insert(bisect_left(dicq[cq], iq), iq)   #更新後に追加 q1 dicq[s[iq]].pop(bisect_left(dicq[s[iq]], iq)) [s[iq]].pop [s[iq]] dicq s[iq] s iq pop bisect_left(dicq[s[iq]], iq) bisect_left dicq[s[iq]] dicq s[iq] s iq iq s[iq] = cq s[iq] s iq cq dicq[cq].insert(bisect_left(dicq[cq], iq), iq) [cq].insert [cq] dicq cq insert bisect_left(dicq[cq], iq) bisect_left dicq[cq] dicq cq iq iq iq iq cq cq def q2(l, r):
    ret = 0
    for ai in al:
        if len(dicq[ai])==0: continue
        li = bisect_left(dicq[ai], l)
        ri = bisect_right(dicq[ai], r)
        if li != ri:
            ret += 1
        elif li == len(dicq[ai]): continue
        elif dicq[ai][li] == l:
            ret += 1
    #    print(l,r,ai,dicq[ai],li,ri,ret)
    print(ret) q2 ret = 0 ret 0 for ai in al:
        if len(dicq[ai])==0: continue
        li = bisect_left(dicq[ai], l)
        ri = bisect_right(dicq[ai], r)
        if li != ri:
            ret += 1
        elif li == len(dicq[ai]): continue
        elif dicq[ai][li] == l:
            ret += 1
    #    print(l,r,ai,dicq[ai],li,ri,ret)
     ai al if len(dicq[ai])==0: continue
         len(dicq[ai])==0 len(dicq[ai]) len dicq[ai] dicq ai 0 li = bisect_left(dicq[ai], l) li bisect_left(dicq[ai], l) bisect_left dicq[ai] dicq ai l ri = bisect_right(dicq[ai], r) ri bisect_right(dicq[ai], r) bisect_right dicq[ai] dicq ai r if li != ri:
            ret += 1
        elif li == len(dicq[ai]): continue
        elif dicq[ai][li] == l:
            ret += 1
    #    print(l,r,ai,dicq[ai],li,ri,ret)
     li != ri li ri ret += 1 ret 1 elif li == len(dicq[ai]): continue
         li == len(dicq[ai]) li len(dicq[ai]) len dicq[ai] dicq ai elif dicq[ai][li] == l:
            ret += 1
    #    print(l,r,ai,dicq[ai],li,ri,ret)
     dicq[ai][li] == l dicq[ai][li] [ai] dicq ai li l ret += 1 ret 1 print(ret) print ret l l r r for i in range(q):
    fg, x, y = input().split()
    if fg == '1':
        q1(int(x)-1, y)
    else:
        q2(int(x)-1, int(y)-1) i range(q) range q fg, x, y = input().split() fg input().split() ().split () input split x y if fg == '1':
        q1(int(x)-1, y)
    else:
        q2(int(x)-1, int(y)-1) fg == '1' fg '1' q1(int(x)-1, y) q1 int(x)-1 int(x) int x 1 y q2(int(x)-1, int(y)-1) q2 int(x)-1 int(x) int x 1 int(y)-1 int(y) int y 1 dicq = {i:[] for i in al} {i:[] for i in al} dicq y = input().split() input().split() y n = int(input()) int(input()) n al = 'abcdefghijklmnopqrstuvwxyz' 'abcdefghijklmnopqrstuvwxyz' al def q1(iq, cq):
    #print(iq,cq,s[iq],dicq[s[iq]],bisect_left(dicq[s[iq]], iq))
    dicq[s[iq]].pop(bisect_left(dicq[s[iq]], iq))   #更新前から削除
    s[iq] = cq
    dicq[cq].insert(bisect_left(dicq[cq], iq), iq)   #更新後に追加 def q1(iq, cq):
    #print(iq,cq,s[iq],dicq[s[iq]],bisect_left(dicq[s[iq]], iq))
    dicq[s[iq]].pop(bisect_left(dicq[s[iq]], iq))   #更新前から削除
    s[iq] = cq
    dicq[cq].insert(bisect_left(dicq[cq], iq), iq)   #更新後に追加 q1 fg, x, y = input().split() input().split() fg q = int(input()) int(input()) q x, y = input().split() input().split() x s = list(input()) list(input()) s def q2(l, r):
    ret = 0
    for ai in al:
        if len(dicq[ai])==0: continue
        li = bisect_left(dicq[ai], l)
        ri = bisect_right(dicq[ai], r)
        if li != ri:
            ret += 1
        elif li == len(dicq[ai]): continue
        elif dicq[ai][li] == l:
            ret += 1
    #    print(l,r,ai,dicq[ai],li,ri,ret)
    print(ret) def q2(l, r):
    ret = 0
    for ai in al:
        if len(dicq[ai])==0: continue
        li = bisect_left(dicq[ai], l)
        ri = bisect_right(dicq[ai], r)
        if li != ri:
            ret += 1
        elif li == len(dicq[ai]): continue
        elif dicq[ai][li] == l:
            ret += 1
    #    print(l,r,ai,dicq[ai],li,ri,ret)
    print(ret) q2
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right


n = int(input())
s = list(input())
q = int(input())

al = 'abcdefghijklmnopqrstuvwxyz'
dicq = {i:[] for i in al}
for i, si in enumerate(s):
    dicq[si].append(i)

def q1(iq, cq):
    #print(iq,cq,s[iq],dicq[s[iq]],bisect_left(dicq[s[iq]], iq))
    dicq[s[iq]].pop(bisect_left(dicq[s[iq]], iq))   #更新前から削除
    s[iq] = cq
    dicq[cq].insert(bisect_left(dicq[cq], iq), iq)   #更新後に追加

def q2(l, r):
    ret = 0
    for ai in al:
        if len(dicq[ai])==0: continue
        li = bisect_left(dicq[ai], l)
        ri = bisect_right(dicq[ai], r)
        if li != ri:
            ret += 1
        elif li == len(dicq[ai]): continue
        elif dicq[ai][li] == l:
            ret += 1
    #    print(l,r,ai,dicq[ai],li,ri,ret)
    print(ret)

for i in range(q):
    fg, x, y = input().split()
    if fg == '1':
        q1(int(x)-1, y)
    else:
        q2(int(x)-1, int(y)-1)
