def main():
  N=int(input())
  S=str(input())
  Q=int(input())
  Q1=[]
  Q2=[]
  Q3=[]
  for i in range(Q):
    i1,i2,i3=map(str,input().split())
    Q1+=[i1]
    Q2+=[i2]
    Q3+=[i3]
  Slist=[]
  for i in range(N):
    Slist+=[S[i]]
  tf=[[0 for  i in range(26)] for i in range(N+1)]
  for i in range(1,N):
    n=ord(Slist[i])-97
    tf[i][n]=tf[i-1][n]+1
  for i in range(Q):
    if int(Q1[i])==1:
      n=ord(Slist[int(Q2[i])-1])-97
      tf[int(Q2[i])-1][n]-=1
      Slist[int(Q2[i])-1]=Q3[i]
      n=ord(Q3[i])-97
      tf[int(Q2[i])-1][n]+=1
    elif int(Q1[i])==2:
      l=Q2[i]-2
      r=Q3[i]-1
      t=0
      for i in range(26):
        if tf[r][i]>tf[l][i]:
          t+=1
      print(t)
if __name__ == '__main__':
  main()
