import bisect

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

alphabet="abcdefghijklmnopqrstuvwxyz"
bag={l:[] for l in alphabet}
for i in range(N):
    bag[S[i]].append(i+1)
#print(bag)

for i in range(Q):
    Type,a,b=input().split()
    if Type=='1':
        a=int(a)
        if S[a-1]!=b:
            bag[S[a-1]].remove(a)
            S[a-1]=b
            bisect.insort(bag[b],a)
    else:
        cnt=0
        a,b=int(a),int(b)
        for l in alphabet:
            bl=len(bag[l])
            if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
        print(cnt) import bisect bisect 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 alphabet="abcdefghijklmnopqrstuvwxyz" alphabet "abcdefghijklmnopqrstuvwxyz" l:[] for l in alphabet for l in alphabet l alphabet for l in alphabet l [] bag={l:[] for l in alphabet} bag {l:[] for l in alphabet} for i in range(N):
    bag[S[i]].append(i+1)
#print(bag) i range(N) range N bag[S[i]].append(i+1) [S[i]].append [S[i]] bag S[i] S i append i+1 i 1 for i in range(Q):
    Type,a,b=input().split()
    if Type=='1':
        a=int(a)
        if S[a-1]!=b:
            bag[S[a-1]].remove(a)
            S[a-1]=b
            bisect.insort(bag[b],a)
    else:
        cnt=0
        a,b=int(a),int(b)
        for l in alphabet:
            bl=len(bag[l])
            if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
        print(cnt) i range(Q) range Q Type,a,b=input().split() Type input().split() ().split () input split a b if Type=='1':
        a=int(a)
        if S[a-1]!=b:
            bag[S[a-1]].remove(a)
            S[a-1]=b
            bisect.insort(bag[b],a)
    else:
        cnt=0
        a,b=int(a),int(b)
        for l in alphabet:
            bl=len(bag[l])
            if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
        print(cnt) Type=='1' Type '1' a=int(a) a int(a) int a if S[a-1]!=b:
            bag[S[a-1]].remove(a)
            S[a-1]=b
            bisect.insort(bag[b],a)
     S[a-1]!=b S[a-1] S a-1 a 1 b bag[S[a-1]].remove(a) [S[a-1]].remove [S[a-1]] bag S[a-1] S a-1 a 1 remove a S[a-1]=b S[a-1] S a-1 a 1 b bisect.insort(bag[b],a) bisect.insort bisect insort bag[b] bag b a cnt=0 cnt 0 a,b=int(a),int(b) a int(a) int a b int(b) int b for l in alphabet:
            bl=len(bag[l])
            if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
         l alphabet bl=len(bag[l]) bl len(bag[l]) len bag[l] bag l if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
         bl>0 bl 0 left=bisect.bisect_left(bag[l],a) left bisect.bisect_left(bag[l],a) bisect.bisect_left bisect bisect_left bag[l] bag l a if left!=bl and bag[l][left]<=b:
                        cnt+=1
         left!=bl and bag[l][left]<=b left!=bl left bl bag[l][left]<=b bag[l][left] [l] bag l left b cnt+=1 cnt 1 print(cnt) print cnt Type,a,b=input().split() input().split() Type S=list(input()) list(input()) S a,b=int(a),int(b) int(a) a b=int(a),int(b) int(b) b Q=int(input()) int(input()) Q b=input().split() input().split() b bl=len(bag[l]) len(bag[l]) bl cnt+=1 1 cnt bag={l:[] for l in alphabet} {l:[] for l in alphabet} bag N=int(input()) int(input()) N a,b=input().split() input().split() a left=bisect.bisect_left(bag[l],a) bisect.bisect_left(bag[l],a) left alphabet="abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alphabet a=int(a) int(a) a cnt=0 0 cnt
import bisect

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

alphabet="abcdefghijklmnopqrstuvwxyz"
bag={l:[] for l in alphabet}
for i in range(N):
    bag[S[i]].append(i+1)
#print(bag)

for i in range(Q):
    Type,a,b=input().split()
    if Type=='1':
        a=int(a)
        if S[a-1]!=b:
            bag[S[a-1]].remove(a)
            S[a-1]=b
            bisect.insort(bag[b],a)
    else:
        cnt=0
        a,b=int(a),int(b)
        for l in alphabet:
            bl=len(bag[l])
            if bl>0:
                left=bisect.bisect_left(bag[l],a)
                if left!=bl and bag[l][left]<=b:
                        cnt+=1
        print(cnt)