from bisect import bisect_left
import string 

dic={c:[] for c in string.ascii_lowercase}
N=int(input())
S=list(input())
Q=int(input())
for i in range(len(S)):
  dic[S[i]].append(i+1)

for i in range(Q):
  a,b,c=map(str,input().split())
  if a=='1':
    if S[int(b)-1]==c:
      continue
    b=int(b)
    f=S[b-1]
    d=bisect_left(dic[f],b)
    e=bisect_left(dic[c],b)
    dic[f].pop(d)
    dic[c].insert(e,b)
    S[b-1]=c
  else:
    ans=0
    b,c=int(b),int(c)
    for j in string.ascii_lowercase:
      d=bisect_left(dic[j],b)
      if d<len(dic[j]):
        if dic[j][d]<=c:
          ans+=1
    print(ans) from bisect import bisect_left import string string c:[] for c in string.ascii_lowercase for c in string.ascii_lowercase c string.ascii_lowercase string ascii_lowercase for c in string.ascii_lowercase c [] dic={c:[] for c in string.ascii_lowercase} dic {c:[] for c in string.ascii_lowercase} 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 for i in range(len(S)):
  dic[S[i]].append(i+1) i range(len(S)) range len(S) len S dic[S[i]].append(i+1) [S[i]].append [S[i]] dic S[i] S i append i+1 i 1 for i in range(Q):
  a,b,c=map(str,input().split())
  if a=='1':
    if S[int(b)-1]==c:
      continue
    b=int(b)
    f=S[b-1]
    d=bisect_left(dic[f],b)
    e=bisect_left(dic[c],b)
    dic[f].pop(d)
    dic[c].insert(e,b)
    S[b-1]=c
  else:
    ans=0
    b,c=int(b),int(c)
    for j in string.ascii_lowercase:
      d=bisect_left(dic[j],b)
      if d<len(dic[j]):
        if dic[j][d]<=c:
          ans+=1
    print(ans) i range(Q) range Q a,b,c=map(str,input().split()) a map(str,input().split()) map str input().split() ().split () input split b c if a=='1':
    if S[int(b)-1]==c:
      continue
    b=int(b)
    f=S[b-1]
    d=bisect_left(dic[f],b)
    e=bisect_left(dic[c],b)
    dic[f].pop(d)
    dic[c].insert(e,b)
    S[b-1]=c
  else:
    ans=0
    b,c=int(b),int(c)
    for j in string.ascii_lowercase:
      d=bisect_left(dic[j],b)
      if d<len(dic[j]):
        if dic[j][d]<=c:
          ans+=1
    print(ans) a=='1' a '1' if S[int(b)-1]==c:
      continue
     S[int(b)-1]==c S[int(b)-1] S int(b)-1 int(b) int b 1 c continue b=int(b) b int(b) int b f=S[b-1] f S[b-1] S b-1 b 1 d=bisect_left(dic[f],b) d bisect_left(dic[f],b) bisect_left dic[f] dic f b e=bisect_left(dic[c],b) e bisect_left(dic[c],b) bisect_left dic[c] dic c b dic[f].pop(d) [f].pop [f] dic f pop d dic[c].insert(e,b) [c].insert [c] dic c insert e b S[b-1]=c S[b-1] S b-1 b 1 c ans=0 ans 0 b,c=int(b),int(c) b int(b) int b c int(c) int c for j in string.ascii_lowercase:
      d=bisect_left(dic[j],b)
      if d<len(dic[j]):
        if dic[j][d]<=c:
          ans+=1
     j string.ascii_lowercase string ascii_lowercase d=bisect_left(dic[j],b) d bisect_left(dic[j],b) bisect_left dic[j] dic j b if d<len(dic[j]):
        if dic[j][d]<=c:
          ans+=1
     d<len(dic[j]) d len(dic[j]) len dic[j] dic j if dic[j][d]<=c:
          ans+=1
     dic[j][d]<=c dic[j][d] [j] dic j d c ans+=1 ans 1 print(ans) print ans S=list(input()) list(input()) S d=bisect_left(dic[f],b) bisect_left(dic[f],b) d b,c=int(b),int(c) int(b) b c=int(b),int(c) int(c) c c=map(str,input().split()) map(str,input().split()) c d=bisect_left(dic[j],b) bisect_left(dic[j],b) d Q=int(input()) int(input()) Q ans+=1 1 ans e=bisect_left(dic[c],b) bisect_left(dic[c],b) e ans=0 0 ans N=int(input()) int(input()) N dic={c:[] for c in string.ascii_lowercase} {c:[] for c in string.ascii_lowercase} dic b,c=map(str,input().split()) map(str,input().split()) b f=S[b-1] S[b-1] f a,b,c=map(str,input().split()) map(str,input().split()) a b=int(b) int(b) b
from bisect import bisect_left
import string 

dic={c:[] for c in string.ascii_lowercase}
N=int(input())
S=list(input())
Q=int(input())
for i in range(len(S)):
  dic[S[i]].append(i+1)

for i in range(Q):
  a,b,c=map(str,input().split())
  if a=='1':
    if S[int(b)-1]==c:
      continue
    b=int(b)
    f=S[b-1]
    d=bisect_left(dic[f],b)
    e=bisect_left(dic[c],b)
    dic[f].pop(d)
    dic[c].insert(e,b)
    S[b-1]=c
  else:
    ans=0
    b,c=int(b),int(c)
    for j in string.ascii_lowercase:
      d=bisect_left(dic[j],b)
      if d<len(dic[j]):
        if dic[j][d]<=c:
          ans+=1
    print(ans)
