from bisect import bisect_left,bisect_right

TO_ACII = 97

N = int(input())
S = ["0"] + list(input())
Q = int(input())

ABC = [[]for i in range(0,26,1)]#該当文字a:0 b:1 ...z:26 が何文字目に出てきたかを保持する配列

for i in range(1,N+1,1):
    ABC[ord(S[i])-TO_ACII].append(i)

ans = []
for i in range(0,Q,1):
    q = list(input().split())
    if q[0]=="1":#文字変更
        changed = S[int(q[1])]
        ABC[ord(changed)-TO_ACII].pop(bisect_left(ABC[ord(changed)-TO_ACII],int(q[1])))
        ABC[ord(q[2])-TO_ACII].insert(bisect_left(ABC[ord(q[2])-TO_ACII],int(q[1])),int(q[1]))
        S[int(q[1])]=q[2]
    else:
        tmpans = 0
        for i in range(0,26,1):

            if bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) and int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)]:
                tmpans+=1
        ans.append(tmpans)

for i in range(0,len(ans),1):
    print(ans[i]) from bisect import bisect_left,bisect_right TO_ACII = 97 TO_ACII 97 N = int(input()) N int(input()) int input() input S = ["0"] + list(input()) S ["0"] + list(input()) ["0"] "0" list(input()) list input() input Q = int(input()) Q int(input()) int input() input []for i in range(0,26,1) for i in range(0,26,1) i range(0,26,1) range 0 26 1 for i in range(0,26,1) [] ABC = [[]for i in range(0,26,1)] ABC [[]for i in range(0,26,1)] for i in range(1,N+1,1):
    ABC[ord(S[i])-TO_ACII].append(i) i range(1,N+1,1) range 1 N+1 N 1 1 ABC[ord(S[i])-TO_ACII].append(i) [ord(S[i])-TO_ACII].append [ord(S[i])-TO_ACII] ABC ord(S[i])-TO_ACII ord(S[i]) ord S[i] S i TO_ACII append i ans = [] ans [] for i in range(0,Q,1):
    q = list(input().split())
    if q[0]=="1":#文字変更
        changed = S[int(q[1])]
        ABC[ord(changed)-TO_ACII].pop(bisect_left(ABC[ord(changed)-TO_ACII],int(q[1])))
        ABC[ord(q[2])-TO_ACII].insert(bisect_left(ABC[ord(q[2])-TO_ACII],int(q[1])),int(q[1]))
        S[int(q[1])]=q[2]
    else:
        tmpans = 0
        for i in range(0,26,1):

            if bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) and int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)]:
                tmpans+=1
        ans.append(tmpans) i range(0,Q,1) range 0 Q 1 q = list(input().split()) q list(input().split()) list input().split() ().split () input split if q[0]=="1":#文字変更
        changed = S[int(q[1])]
        ABC[ord(changed)-TO_ACII].pop(bisect_left(ABC[ord(changed)-TO_ACII],int(q[1])))
        ABC[ord(q[2])-TO_ACII].insert(bisect_left(ABC[ord(q[2])-TO_ACII],int(q[1])),int(q[1]))
        S[int(q[1])]=q[2]
    else:
        tmpans = 0
        for i in range(0,26,1):

            if bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) and int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)]:
                tmpans+=1
        ans.append(tmpans) q[0]=="1" q[0] q 0 "1" changed = S[int(q[1])] changed S[int(q[1])] S int(q[1]) int q[1] q 1 ABC[ord(changed)-TO_ACII].pop(bisect_left(ABC[ord(changed)-TO_ACII],int(q[1]))) [ord(changed)-TO_ACII].pop [ord(changed)-TO_ACII] ABC ord(changed)-TO_ACII ord(changed) ord changed TO_ACII pop bisect_left(ABC[ord(changed)-TO_ACII],int(q[1])) bisect_left ABC[ord(changed)-TO_ACII] ABC ord(changed)-TO_ACII ord(changed) ord changed TO_ACII int(q[1]) int q[1] q 1 ABC[ord(q[2])-TO_ACII].insert(bisect_left(ABC[ord(q[2])-TO_ACII],int(q[1])),int(q[1])) [ord(q[2])-TO_ACII].insert [ord(q[2])-TO_ACII] ABC ord(q[2])-TO_ACII ord(q[2]) ord q[2] q 2 TO_ACII insert bisect_left(ABC[ord(q[2])-TO_ACII],int(q[1])) bisect_left ABC[ord(q[2])-TO_ACII] ABC ord(q[2])-TO_ACII ord(q[2]) ord q[2] q 2 TO_ACII int(q[1]) int q[1] q 1 int(q[1]) int q[1] q 1 S[int(q[1])]=q[2] S[int(q[1])] S int(q[1]) int q[1] q 1 q[2] q 2 tmpans = 0 tmpans 0 for i in range(0,26,1):

            if bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) and int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)]:
                tmpans+=1
         i range(0,26,1) range 0 26 1 if bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) and int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)]:
                tmpans+=1
         bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) and int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)] bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) bisect_right(ABC[i],int(q[1])-1) bisect_right ABC[i] ABC i int(q[1])-1 int(q[1]) int q[1] q 1 1 len(ABC[i]) len ABC[i] ABC i int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)] int(q[2]) int q[2] q 2 ABC[i][bisect_right(ABC[i],int(q[1])-1)] [i] ABC i bisect_right(ABC[i],int(q[1])-1) bisect_right ABC[i] ABC i int(q[1])-1 int(q[1]) int q[1] q 1 1 tmpans+=1 tmpans 1 ans.append(tmpans) ans.append ans append tmpans for i in range(0,len(ans),1):
    print(ans[i]) i range(0,len(ans),1) range 0 len(ans) len ans 1 print(ans[i]) print ans[i] ans i q = list(input().split()) list(input().split()) q tmpans+=1 1 tmpans TO_ACII = 97 97 TO_ACII Q = int(input()) int(input()) Q ABC = [[]for i in range(0,26,1)] [[]for i in range(0,26,1)] ABC ans = [] [] ans tmpans = 0 0 tmpans S = ["0"] + list(input()) ["0"] + list(input()) S N = int(input()) int(input()) N changed = S[int(q[1])] S[int(q[1])] changed
from bisect import bisect_left,bisect_right

TO_ACII = 97

N = int(input())
S = ["0"] + list(input())
Q = int(input())

ABC = [[]for i in range(0,26,1)]#該当文字a:0 b:1 ...z:26 が何文字目に出てきたかを保持する配列

for i in range(1,N+1,1):
    ABC[ord(S[i])-TO_ACII].append(i)

ans = []
for i in range(0,Q,1):
    q = list(input().split())
    if q[0]=="1":#文字変更
        changed = S[int(q[1])]
        ABC[ord(changed)-TO_ACII].pop(bisect_left(ABC[ord(changed)-TO_ACII],int(q[1])))
        ABC[ord(q[2])-TO_ACII].insert(bisect_left(ABC[ord(q[2])-TO_ACII],int(q[1])),int(q[1]))
        S[int(q[1])]=q[2]
    else:
        tmpans = 0
        for i in range(0,26,1):

            if bisect_right(ABC[i],int(q[1])-1)<len(ABC[i]) and int(q[2]) >= ABC[i][bisect_right(ABC[i],int(q[1])-1)]:
                tmpans+=1
        ans.append(tmpans)

for i in range(0,len(ans),1):
    print(ans[i])
