import sys
input=sys.stdin.readline

def init():
    #set_val
    #for j in range(26):
    #  for i in range(n):
    #    seg[j][i+num-1]=init_val[i]    
    #built
    for j in range(26):
      for i in range(num-2,-1,-1) :
        seg[j][i]=max(seg[j][2*i+1],seg[j][2*i+2]) 
    
def update(k,x):
    K =k+num-1
    seg[SS[k]][K] = 0
    while K:
        K = (K-1)//2
        seg[SS[k]][K] = max(seg[SS[k]][K*2+1],seg[SS[k]][K*2+2])
    K =k+num-1
    seg[x][K]=1
    while K:
      K=(K-1)//2
      seg[x][K]=max(seg[x][K*2+1],seg[x][K*2+2])
    SS[k]=x
    
def query(p,q):
  a=0
  for i in range(26):
    P =p+ num-1
    Q =q+ num-1
    res=ide_ele
    while Q-P>1:
        if P&1 == 0:
            res = max(res,seg[i][P])
        if Q&1 == 1:
            res = max(res,seg[i][Q])
            Q -= 1
        P = P//2
        Q = (Q-1)//2
    if P == Q:
        res = max(res,seg[i][Q])
    else:
        res = max(max(res,seg[i][P]),seg[i][Q])
    a=a+res
  print(a)
  return a

n=int(input())
S=input()
q=int(input())


#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[[ide_ele]*2*num for i in range(26)]


SS=[0]*num
for i in range(n):
  seg[ord(S[i])-97][i+num-1]=1
  SS[i]=ord(S[i])-97
#print(SS)
#print(seg)
init()
#print(seg)

for xx in range(q):
  SSS=list(input().split())
  #print(SSS)
  if SSS[0]=="1":
    #print(int(SSS[1])-1,ord(SSS[2])-97)
    update(int(SSS[1])-1,ord(SSS[2])-97)
  else:
    query(int(SSS[1])-1,int(SSS[2])-1)
#print(seg) import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def init():
    #set_val
    #for j in range(26):
    #  for i in range(n):
    #    seg[j][i+num-1]=init_val[i]    
    #built
    for j in range(26):
      for i in range(num-2,-1,-1) :
        seg[j][i]=max(seg[j][2*i+1],seg[j][2*i+2]) 
     init for j in range(26):
      for i in range(num-2,-1,-1) :
        seg[j][i]=max(seg[j][2*i+1],seg[j][2*i+2]) 
     j range(26) range 26 for i in range(num-2,-1,-1) :
        seg[j][i]=max(seg[j][2*i+1],seg[j][2*i+2]) 
     i range(num-2,-1,-1) range num-2 num 2 -1 -1 seg[j][i]=max(seg[j][2*i+1],seg[j][2*i+2]) seg[j][i] [j] seg j i max(seg[j][2*i+1],seg[j][2*i+2]) max seg[j][2*i+1] [j] seg j 2*i+1 2*i 2 i 1 seg[j][2*i+2] [j] seg j 2*i+2 2*i 2 i 2 def update(k,x):
    K =k+num-1
    seg[SS[k]][K] = 0
    while K:
        K = (K-1)//2
        seg[SS[k]][K] = max(seg[SS[k]][K*2+1],seg[SS[k]][K*2+2])
    K =k+num-1
    seg[x][K]=1
    while K:
      K=(K-1)//2
      seg[x][K]=max(seg[x][K*2+1],seg[x][K*2+2])
    SS[k]=x
     update K =k+num-1 K k+num-1 k+num k num 1 seg[SS[k]][K] = 0 seg[SS[k]][K] [SS[k]] seg SS[k] SS k K 0 while K:
        K = (K-1)//2
        seg[SS[k]][K] = max(seg[SS[k]][K*2+1],seg[SS[k]][K*2+2])
     K K = (K-1)//2 K (K-1)//2 K-1 K 1 2 seg[SS[k]][K] = max(seg[SS[k]][K*2+1],seg[SS[k]][K*2+2]) seg[SS[k]][K] [SS[k]] seg SS[k] SS k K max(seg[SS[k]][K*2+1],seg[SS[k]][K*2+2]) max seg[SS[k]][K*2+1] [SS[k]] seg SS[k] SS k K*2+1 K*2 K 2 1 seg[SS[k]][K*2+2] [SS[k]] seg SS[k] SS k K*2+2 K*2 K 2 2 K =k+num-1 K k+num-1 k+num k num 1 seg[x][K]=1 seg[x][K] [x] seg x K 1 while K:
      K=(K-1)//2
      seg[x][K]=max(seg[x][K*2+1],seg[x][K*2+2])
     K K=(K-1)//2 K (K-1)//2 K-1 K 1 2 seg[x][K]=max(seg[x][K*2+1],seg[x][K*2+2]) seg[x][K] [x] seg x K max(seg[x][K*2+1],seg[x][K*2+2]) max seg[x][K*2+1] [x] seg x K*2+1 K*2 K 2 1 seg[x][K*2+2] [x] seg x K*2+2 K*2 K 2 2 SS[k]=x SS[k] SS k x k k x x def query(p,q):
  a=0
  for i in range(26):
    P =p+ num-1
    Q =q+ num-1
    res=ide_ele
    while Q-P>1:
        if P&1 == 0:
            res = max(res,seg[i][P])
        if Q&1 == 1:
            res = max(res,seg[i][Q])
            Q -= 1
        P = P//2
        Q = (Q-1)//2
    if P == Q:
        res = max(res,seg[i][Q])
    else:
        res = max(max(res,seg[i][P]),seg[i][Q])
    a=a+res
  print(a)
  return a query a=0 a 0 for i in range(26):
    P =p+ num-1
    Q =q+ num-1
    res=ide_ele
    while Q-P>1:
        if P&1 == 0:
            res = max(res,seg[i][P])
        if Q&1 == 1:
            res = max(res,seg[i][Q])
            Q -= 1
        P = P//2
        Q = (Q-1)//2
    if P == Q:
        res = max(res,seg[i][Q])
    else:
        res = max(max(res,seg[i][P]),seg[i][Q])
    a=a+res
   i range(26) range 26 P =p+ num-1 P p+ num-1 p+ num p num 1 Q =q+ num-1 Q q+ num-1 q+ num q num 1 res=ide_ele res ide_ele while Q-P>1:
        if P&1 == 0:
            res = max(res,seg[i][P])
        if Q&1 == 1:
            res = max(res,seg[i][Q])
            Q -= 1
        P = P//2
        Q = (Q-1)//2
     Q-P>1 Q-P Q P 1 if P&1 == 0:
            res = max(res,seg[i][P])
         P&1 == 0 P&1 P 1 0 res = max(res,seg[i][P]) res max(res,seg[i][P]) max res seg[i][P] [i] seg i P if Q&1 == 1:
            res = max(res,seg[i][Q])
            Q -= 1
         Q&1 == 1 Q&1 Q 1 1 res = max(res,seg[i][Q]) res max(res,seg[i][Q]) max res seg[i][Q] [i] seg i Q Q -= 1 Q 1 P = P//2 P P//2 P 2 Q = (Q-1)//2 Q (Q-1)//2 Q-1 Q 1 2 if P == Q:
        res = max(res,seg[i][Q])
    else:
        res = max(max(res,seg[i][P]),seg[i][Q])
     P == Q P Q res = max(res,seg[i][Q]) res max(res,seg[i][Q]) max res seg[i][Q] [i] seg i Q res = max(max(res,seg[i][P]),seg[i][Q]) res max(max(res,seg[i][P]),seg[i][Q]) max max(res,seg[i][P]) max res seg[i][P] [i] seg i P seg[i][Q] [i] seg i Q a=a+res a a+res a res print(a) print a return a a p p q q n=int(input()) n int(input()) int input() input S=input() S input() input q=int(input()) q int(input()) int input() input ide_ele = 0 ide_ele 0 num =2**(n-1).bit_length() num 2**(n-1).bit_length() 2 (n-1).bit_length() n-1).bit_length n-1 n 1 bit_length [ide_ele]*2*num for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) [ide_ele]*2*num [ide_ele]*2 [ide_ele] ide_ele 2 num seg=[[ide_ele]*2*num for i in range(26)] seg [[ide_ele]*2*num for i in range(26)] SS=[0]*num SS [0]*num [0] 0 num for i in range(n):
  seg[ord(S[i])-97][i+num-1]=1
  SS[i]=ord(S[i])-97
#print(SS)
#print(seg) i range(n) range n seg[ord(S[i])-97][i+num-1]=1 seg[ord(S[i])-97][i+num-1] [ord(S[i])-97] seg ord(S[i])-97 ord(S[i]) ord S[i] S i 97 i+num-1 i+num i num 1 1 SS[i]=ord(S[i])-97 SS[i] SS i ord(S[i])-97 ord(S[i]) ord S[i] S i 97 init() init for xx in range(q):
  SSS=list(input().split())
  #print(SSS)
  if SSS[0]=="1":
    #print(int(SSS[1])-1,ord(SSS[2])-97)
    update(int(SSS[1])-1,ord(SSS[2])-97)
  else:
    query(int(SSS[1])-1,int(SSS[2])-1)
#print(seg) xx range(q) range q SSS=list(input().split()) SSS list(input().split()) list input().split() ().split () input split if SSS[0]=="1":
    #print(int(SSS[1])-1,ord(SSS[2])-97)
    update(int(SSS[1])-1,ord(SSS[2])-97)
  else:
    query(int(SSS[1])-1,int(SSS[2])-1)
#print(seg) SSS[0]=="1" SSS[0] SSS 0 "1" update(int(SSS[1])-1,ord(SSS[2])-97) update int(SSS[1])-1 int(SSS[1]) int SSS[1] SSS 1 1 ord(SSS[2])-97 ord(SSS[2]) ord SSS[2] SSS 2 97 query(int(SSS[1])-1,int(SSS[2])-1) query int(SSS[1])-1 int(SSS[1]) int SSS[1] SSS 1 1 int(SSS[2])-1 int(SSS[2]) int SSS[2] SSS 2 1 n=int(input()) int(input()) n SS=[0]*num [0]*num SS input=sys.stdin.readline sys.stdin.readline input def query(p,q):
  a=0
  for i in range(26):
    P =p+ num-1
    Q =q+ num-1
    res=ide_ele
    while Q-P>1:
        if P&1 == 0:
            res = max(res,seg[i][P])
        if Q&1 == 1:
            res = max(res,seg[i][Q])
            Q -= 1
        P = P//2
        Q = (Q-1)//2
    if P == Q:
        res = max(res,seg[i][Q])
    else:
        res = max(max(res,seg[i][P]),seg[i][Q])
    a=a+res
  print(a)
  return a def query(p,q):
  a=0
  for i in range(26):
    P =p+ num-1
    Q =q+ num-1
    res=ide_ele
    while Q-P>1:
        if P&1 == 0:
            res = max(res,seg[i][P])
        if Q&1 == 1:
            res = max(res,seg[i][Q])
            Q -= 1
        P = P//2
        Q = (Q-1)//2
    if P == Q:
        res = max(res,seg[i][Q])
    else:
        res = max(max(res,seg[i][P]),seg[i][Q])
    a=a+res
  print(a)
  return a query num =2**(n-1).bit_length() 2**(n-1).bit_length() num S=input() input() S seg=[[ide_ele]*2*num for i in range(26)] [[ide_ele]*2*num for i in range(26)] seg def update(k,x):
    K =k+num-1
    seg[SS[k]][K] = 0
    while K:
        K = (K-1)//2
        seg[SS[k]][K] = max(seg[SS[k]][K*2+1],seg[SS[k]][K*2+2])
    K =k+num-1
    seg[x][K]=1
    while K:
      K=(K-1)//2
      seg[x][K]=max(seg[x][K*2+1],seg[x][K*2+2])
    SS[k]=x
     def update(k,x):
    K =k+num-1
    seg[SS[k]][K] = 0
    while K:
        K = (K-1)//2
        seg[SS[k]][K] = max(seg[SS[k]][K*2+1],seg[SS[k]][K*2+2])
    K =k+num-1
    seg[x][K]=1
    while K:
      K=(K-1)//2
      seg[x][K]=max(seg[x][K*2+1],seg[x][K*2+2])
    SS[k]=x
     update SSS=list(input().split()) list(input().split()) SSS def init():
    #set_val
    #for j in range(26):
    #  for i in range(n):
    #    seg[j][i+num-1]=init_val[i]    
    #built
    for j in range(26):
      for i in range(num-2,-1,-1) :
        seg[j][i]=max(seg[j][2*i+1],seg[j][2*i+2]) 
     def init():
    #set_val
    #for j in range(26):
    #  for i in range(n):
    #    seg[j][i+num-1]=init_val[i]    
    #built
    for j in range(26):
      for i in range(num-2,-1,-1) :
        seg[j][i]=max(seg[j][2*i+1],seg[j][2*i+2]) 
     init q=int(input()) int(input()) q ide_ele = 0 0 ide_ele
import sys
input=sys.stdin.readline

def init():
    #set_val
    #for j in range(26):
    #  for i in range(n):
    #    seg[j][i+num-1]=init_val[i]    
    #built
    for j in range(26):
      for i in range(num-2,-1,-1) :
        seg[j][i]=max(seg[j][2*i+1],seg[j][2*i+2]) 
    
def update(k,x):
    K =k+num-1
    seg[SS[k]][K] = 0
    while K:
        K = (K-1)//2
        seg[SS[k]][K] = max(seg[SS[k]][K*2+1],seg[SS[k]][K*2+2])
    K =k+num-1
    seg[x][K]=1
    while K:
      K=(K-1)//2
      seg[x][K]=max(seg[x][K*2+1],seg[x][K*2+2])
    SS[k]=x
    
def query(p,q):
  a=0
  for i in range(26):
    P =p+ num-1
    Q =q+ num-1
    res=ide_ele
    while Q-P>1:
        if P&1 == 0:
            res = max(res,seg[i][P])
        if Q&1 == 1:
            res = max(res,seg[i][Q])
            Q -= 1
        P = P//2
        Q = (Q-1)//2
    if P == Q:
        res = max(res,seg[i][Q])
    else:
        res = max(max(res,seg[i][P]),seg[i][Q])
    a=a+res
  print(a)
  return a

n=int(input())
S=input()
q=int(input())


#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[[ide_ele]*2*num for i in range(26)]


SS=[0]*num
for i in range(n):
  seg[ord(S[i])-97][i+num-1]=1
  SS[i]=ord(S[i])-97
#print(SS)
#print(seg)
init()
#print(seg)

for xx in range(q):
  SSS=list(input().split())
  #print(SSS)
  if SSS[0]=="1":
    #print(int(SSS[1])-1,ord(SSS[2])-97)
    update(int(SSS[1])-1,ord(SSS[2])-97)
  else:
    query(int(SSS[1])-1,int(SSS[2])-1)
#print(seg)