import bisect
N=input()
S=list(input())
alphabet=[[] for _ in range(26)]
for i,s in enumerate(S):
    alphabet[ord(s)-ord('a')].append(i)
Q=int(input())
for _ in range(Q):
    Type,A,B=input().split()
    if Type=="1":
        A=int(A)
        s=S[A-1]
        if s==B:
            continue
        o=ord(s)-ord("a")
        alphabet[o].pop(bisect.bisect_left(alphabet[o],A-1))
        index=bisect.bisect(alphabet[ord(B)-ord("a")],A-1)
        alphabet[ord(B)-ord("a")].insert(index,A-1)
        S[A-1]=B
    else:
        A=int(A)
        B=int(B)
        ans=0
        for i in range(26):
            indexL=bisect.bisect_left(alphabet[i],A-1)
            #indexR=bisect.bisect_right(alphabet[i],B-1)
            #ans+=(indexL!=indexR)
            if indexL==len(alphabet[i]):
                continue
            ans+=(alphabet[i][indexL]<=B-1)
        print(ans) import bisect bisect N=input() N input() input S=list(input()) S list(input()) list input() input [] for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [] alphabet=[[] for _ in range(26)] alphabet [[] for _ in range(26)] for i,s in enumerate(S):
    alphabet[ord(s)-ord('a')].append(i) i s enumerate(S) enumerate S alphabet[ord(s)-ord('a')].append(i) [ord(s)-ord('a')].append [ord(s)-ord('a')] alphabet ord(s)-ord('a') ord(s) ord s ord('a') ord 'a' append i Q=int(input()) Q int(input()) int input() input for _ in range(Q):
    Type,A,B=input().split()
    if Type=="1":
        A=int(A)
        s=S[A-1]
        if s==B:
            continue
        o=ord(s)-ord("a")
        alphabet[o].pop(bisect.bisect_left(alphabet[o],A-1))
        index=bisect.bisect(alphabet[ord(B)-ord("a")],A-1)
        alphabet[ord(B)-ord("a")].insert(index,A-1)
        S[A-1]=B
    else:
        A=int(A)
        B=int(B)
        ans=0
        for i in range(26):
            indexL=bisect.bisect_left(alphabet[i],A-1)
            #indexR=bisect.bisect_right(alphabet[i],B-1)
            #ans+=(indexL!=indexR)
            if indexL==len(alphabet[i]):
                continue
            ans+=(alphabet[i][indexL]<=B-1)
        print(ans) _ range(Q) range Q Type,A,B=input().split() Type input().split() ().split () input split A B if Type=="1":
        A=int(A)
        s=S[A-1]
        if s==B:
            continue
        o=ord(s)-ord("a")
        alphabet[o].pop(bisect.bisect_left(alphabet[o],A-1))
        index=bisect.bisect(alphabet[ord(B)-ord("a")],A-1)
        alphabet[ord(B)-ord("a")].insert(index,A-1)
        S[A-1]=B
    else:
        A=int(A)
        B=int(B)
        ans=0
        for i in range(26):
            indexL=bisect.bisect_left(alphabet[i],A-1)
            #indexR=bisect.bisect_right(alphabet[i],B-1)
            #ans+=(indexL!=indexR)
            if indexL==len(alphabet[i]):
                continue
            ans+=(alphabet[i][indexL]<=B-1)
        print(ans) Type=="1" Type "1" A=int(A) A int(A) int A s=S[A-1] s S[A-1] S A-1 A 1 if s==B:
            continue
         s==B s B continue o=ord(s)-ord("a") o ord(s)-ord("a") ord(s) ord s ord("a") ord "a" alphabet[o].pop(bisect.bisect_left(alphabet[o],A-1)) [o].pop [o] alphabet o pop bisect.bisect_left(alphabet[o],A-1) bisect.bisect_left bisect bisect_left alphabet[o] alphabet o A-1 A 1 index=bisect.bisect(alphabet[ord(B)-ord("a")],A-1) index bisect.bisect(alphabet[ord(B)-ord("a")],A-1) bisect.bisect bisect bisect alphabet[ord(B)-ord("a")] alphabet ord(B)-ord("a") ord(B) ord B ord("a") ord "a" A-1 A 1 alphabet[ord(B)-ord("a")].insert(index,A-1) [ord(B)-ord("a")].insert [ord(B)-ord("a")] alphabet ord(B)-ord("a") ord(B) ord B ord("a") ord "a" insert index A-1 A 1 S[A-1]=B S[A-1] S A-1 A 1 B A=int(A) A int(A) int A B=int(B) B int(B) int B ans=0 ans 0 for i in range(26):
            indexL=bisect.bisect_left(alphabet[i],A-1)
            #indexR=bisect.bisect_right(alphabet[i],B-1)
            #ans+=(indexL!=indexR)
            if indexL==len(alphabet[i]):
                continue
            ans+=(alphabet[i][indexL]<=B-1)
         i range(26) range 26 indexL=bisect.bisect_left(alphabet[i],A-1) indexL bisect.bisect_left(alphabet[i],A-1) bisect.bisect_left bisect bisect_left alphabet[i] alphabet i A-1 A 1 if indexL==len(alphabet[i]):
                continue
             indexL==len(alphabet[i]) indexL len(alphabet[i]) len alphabet[i] alphabet i continue ans+=(alphabet[i][indexL]<=B-1) ans alphabet[i][indexL]<=B-1 alphabet[i][indexL] [i] alphabet i indexL B-1 B 1 print(ans) print ans S=list(input()) list(input()) S ans=0 0 ans ans+=(alphabet[i][indexL]<=B-1) alphabet[i][indexL]<=B-1 ans N=input() input() N B=int(B) int(B) B Type,A,B=input().split() input().split() Type B=input().split() input().split() B A,B=input().split() input().split() A s=S[A-1] S[A-1] s index=bisect.bisect(alphabet[ord(B)-ord("a")],A-1) bisect.bisect(alphabet[ord(B)-ord("a")],A-1) index o=ord(s)-ord("a") ord(s)-ord("a") o A=int(A) int(A) A alphabet=[[] for _ in range(26)] [[] for _ in range(26)] alphabet Q=int(input()) int(input()) Q indexL=bisect.bisect_left(alphabet[i],A-1) bisect.bisect_left(alphabet[i],A-1) indexL A=int(A) int(A) A
import bisect
N=input()
S=list(input())
alphabet=[[] for _ in range(26)]
for i,s in enumerate(S):
    alphabet[ord(s)-ord('a')].append(i)
Q=int(input())
for _ in range(Q):
    Type,A,B=input().split()
    if Type=="1":
        A=int(A)
        s=S[A-1]
        if s==B:
            continue
        o=ord(s)-ord("a")
        alphabet[o].pop(bisect.bisect_left(alphabet[o],A-1))
        index=bisect.bisect(alphabet[ord(B)-ord("a")],A-1)
        alphabet[ord(B)-ord("a")].insert(index,A-1)
        S[A-1]=B
    else:
        A=int(A)
        B=int(B)
        ans=0
        for i in range(26):
            indexL=bisect.bisect_left(alphabet[i],A-1)
            #indexR=bisect.bisect_right(alphabet[i],B-1)
            #ans+=(indexL!=indexR)
            if indexL==len(alphabet[i]):
                continue
            ans+=(alphabet[i][indexL]<=B-1)
        print(ans)
