class SegmentTree: #1-indexed
    def __init__(self,list,a,f=lambda x,y:x+y,inf=0):
        self.height=(len(list)-1).bit_length()+1 #木の高さ
        self.id=inf #単位元
        self.tree=[self.id]*(2**self.height) #木を単位元で初期化
        self.f=f
        for i in range(len(list)):
            if list[i]==a:
                self.tree[2**(self.height-1)+i]=1
        for i in range(2**(self.height-1)-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
    def update(self,i,x): #i番目の要素をxに変更(0-indexed)
        i+=2**(self.height-1)
        self.tree[i]=x
        while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
    def query(self,l,r): #0-indexed
        l+=2**(self.height-1)
        r+=2**(self.height-1)
        lf,rf=self.id,self.id
        while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
        return self.f(lf,rf)
n=int(input())
s=list(input())
q=int(input())
l=[]
for i in range(26):
    l.append(SegmentTree(s,chr(97+i),f=lambda x,y:x or y))
for _ in range(q):
    a,b,c=input().split()
    if a=="1":
        b=int(b)-1
        l[ord(s[b])-97].update(b,0)
        l[ord(c)-97].update(b,1)
        s[b]=c
    else:
        b,c=int(b)-1,int(c)
        count=0
        for i in range(26):
            if l[i].query(b,c):
                count+=1
        print(count) class SegmentTree: #1-indexed
    def __init__(self,list,a,f=lambda x,y:x+y,inf=0):
        self.height=(len(list)-1).bit_length()+1 #木の高さ
        self.id=inf #単位元
        self.tree=[self.id]*(2**self.height) #木を単位元で初期化
        self.f=f
        for i in range(len(list)):
            if list[i]==a:
                self.tree[2**(self.height-1)+i]=1
        for i in range(2**(self.height-1)-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
    def update(self,i,x): #i番目の要素をxに変更(0-indexed)
        i+=2**(self.height-1)
        self.tree[i]=x
        while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
    def query(self,l,r): #0-indexed
        l+=2**(self.height-1)
        r+=2**(self.height-1)
        lf,rf=self.id,self.id
        while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
        return self.f(lf,rf) SegmentTree def __init__(self,list,a,f=lambda x,y:x+y,inf=0):
        self.height=(len(list)-1).bit_length()+1 #木の高さ
        self.id=inf #単位元
        self.tree=[self.id]*(2**self.height) #木を単位元で初期化
        self.f=f
        for i in range(len(list)):
            if list[i]==a:
                self.tree[2**(self.height-1)+i]=1
        for i in range(2**(self.height-1)-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
     __init__ self.height=(len(list)-1).bit_length()+1 self.height self height (len(list)-1).bit_length()+1 (len(list)-1).bit_length() len(list)-1).bit_length len(list)-1 len(list) len list 1 bit_length 1 self.id=inf self.id self id inf self.tree=[self.id]*(2**self.height) self.tree self tree [self.id]*(2**self.height) [self.id] self.id self id 2**self.height 2 self.height self height self.f=f self.f self f f for i in range(len(list)):
            if list[i]==a:
                self.tree[2**(self.height-1)+i]=1
         i range(len(list)) range len(list) len list if list[i]==a:
                self.tree[2**(self.height-1)+i]=1
         list[i]==a list[i] list i a self.tree[2**(self.height-1)+i]=1 self.tree[2**(self.height-1)+i] self.tree self tree 2**(self.height-1)+i 2**(self.height-1) 2 self.height-1 self.height self height 1 i 1 for i in range(2**(self.height-1)-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
     i range(2**(self.height-1)-1,0,-1) range 2**(self.height-1)-1 2**(self.height-1) 2 self.height-1 self.height self height 1 1 0 -1 self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1]) self.tree[i] self.tree self tree i self.f(self.tree[2*i],self.tree[2*i+1]) self.f self f self.tree[2*i] self.tree self tree 2*i 2 i self.tree[2*i+1] self.tree self tree 2*i+1 2*i 2 i 1 self self list list a a f=lambda x,y:x+y f lambda x,y:x+y x+y x y x y inf=0 inf 0 def update(self,i,x): #i番目の要素をxに変更(0-indexed)
        i+=2**(self.height-1)
        self.tree[i]=x
        while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
     update i+=2**(self.height-1) i 2**(self.height-1) 2 self.height-1 self.height self height 1 self.tree[i]=x self.tree[i] self.tree self tree i x while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
     i>1 i 1 i//=2 i 2 self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1]) self.tree[i] self.tree self tree i self.f(self.tree[2*i],self.tree[2*i+1]) self.f self f self.tree[2*i] self.tree self tree 2*i 2 i self.tree[2*i+1] self.tree self tree 2*i+1 2*i 2 i 1 self self i i x x def query(self,l,r): #0-indexed
        l+=2**(self.height-1)
        r+=2**(self.height-1)
        lf,rf=self.id,self.id
        while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
        return self.f(lf,rf) query l+=2**(self.height-1) l 2**(self.height-1) 2 self.height-1 self.height self height 1 r+=2**(self.height-1) r 2**(self.height-1) 2 self.height-1 self.height self height 1 lf,rf=self.id,self.id lf self.id self id rf self.id self id while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
         l<r l r if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
             l&1 l 1 lf=self.f(lf,self.tree[l]) lf self.f(lf,self.tree[l]) self.f self f lf self.tree[l] self.tree self tree l l+=1 l 1 if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
             r&1 r 1 r-=1 r 1 rf=self.f(self.tree[r],rf) rf self.f(self.tree[r],rf) self.f self f self.tree[r] self.tree self tree r rf l//=2 l 2 r//=2 r 2 return self.f(lf,rf) self.f(lf,rf) self.f self f lf rf self self l l r r 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 l=[] l [] for i in range(26):
    l.append(SegmentTree(s,chr(97+i),f=lambda x,y:x or y)) i range(26) range 26 l.append(SegmentTree(s,chr(97+i),f=lambda x,y:x or y)) l.append l append SegmentTree(s,chr(97+i),f=lambda x,y:x or y) SegmentTree s chr(97+i) chr 97+i 97 i f=lambda x,y:x or y f lambda x,y:x or y x or y x y x y for _ in range(q):
    a,b,c=input().split()
    if a=="1":
        b=int(b)-1
        l[ord(s[b])-97].update(b,0)
        l[ord(c)-97].update(b,1)
        s[b]=c
    else:
        b,c=int(b)-1,int(c)
        count=0
        for i in range(26):
            if l[i].query(b,c):
                count+=1
        print(count) _ range(q) range q a,b,c=input().split() a input().split() ().split () input split b c if a=="1":
        b=int(b)-1
        l[ord(s[b])-97].update(b,0)
        l[ord(c)-97].update(b,1)
        s[b]=c
    else:
        b,c=int(b)-1,int(c)
        count=0
        for i in range(26):
            if l[i].query(b,c):
                count+=1
        print(count) a=="1" a "1" b=int(b)-1 b int(b)-1 int(b) int b 1 l[ord(s[b])-97].update(b,0) [ord(s[b])-97].update [ord(s[b])-97] l ord(s[b])-97 ord(s[b]) ord s[b] s b 97 update b 0 l[ord(c)-97].update(b,1) [ord(c)-97].update [ord(c)-97] l ord(c)-97 ord(c) ord c 97 update b 1 s[b]=c s[b] s b c b,c=int(b)-1,int(c) b int(b)-1 int(b) int b 1 c int(c) int c count=0 count 0 for i in range(26):
            if l[i].query(b,c):
                count+=1
         i range(26) range 26 if l[i].query(b,c):
                count+=1
         l[i].query(b,c) [i].query [i] l i query b c count+=1 count 1 print(count) print count count+=1 1 count c=input().split() input().split() c c=int(b)-1,int(c) int(c) c q=int(input()) int(input()) q a,b,c=input().split() input().split() a s=list(input()) list(input()) s b,c=int(b)-1,int(c) int(b)-1 b class SegmentTree: #1-indexed
    def __init__(self,list,a,f=lambda x,y:x+y,inf=0):
        self.height=(len(list)-1).bit_length()+1 #木の高さ
        self.id=inf #単位元
        self.tree=[self.id]*(2**self.height) #木を単位元で初期化
        self.f=f
        for i in range(len(list)):
            if list[i]==a:
                self.tree[2**(self.height-1)+i]=1
        for i in range(2**(self.height-1)-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
    def update(self,i,x): #i番目の要素をxに変更(0-indexed)
        i+=2**(self.height-1)
        self.tree[i]=x
        while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
    def query(self,l,r): #0-indexed
        l+=2**(self.height-1)
        r+=2**(self.height-1)
        lf,rf=self.id,self.id
        while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
        return self.f(lf,rf) class SegmentTree: #1-indexed
    def __init__(self,list,a,f=lambda x,y:x+y,inf=0):
        self.height=(len(list)-1).bit_length()+1 #木の高さ
        self.id=inf #単位元
        self.tree=[self.id]*(2**self.height) #木を単位元で初期化
        self.f=f
        for i in range(len(list)):
            if list[i]==a:
                self.tree[2**(self.height-1)+i]=1
        for i in range(2**(self.height-1)-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
    def update(self,i,x): #i番目の要素をxに変更(0-indexed)
        i+=2**(self.height-1)
        self.tree[i]=x
        while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
    def query(self,l,r): #0-indexed
        l+=2**(self.height-1)
        r+=2**(self.height-1)
        lf,rf=self.id,self.id
        while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
        return self.f(lf,rf) SegmentTree l=[] [] l count=0 0 count b=int(b)-1 int(b)-1 b b,c=input().split() input().split() b n=int(input()) int(input()) n
class SegmentTree: #1-indexed
    def __init__(self,list,a,f=lambda x,y:x+y,inf=0):
        self.height=(len(list)-1).bit_length()+1 #木の高さ
        self.id=inf #単位元
        self.tree=[self.id]*(2**self.height) #木を単位元で初期化
        self.f=f
        for i in range(len(list)):
            if list[i]==a:
                self.tree[2**(self.height-1)+i]=1
        for i in range(2**(self.height-1)-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
    def update(self,i,x): #i番目の要素をxに変更(0-indexed)
        i+=2**(self.height-1)
        self.tree[i]=x
        while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
    def query(self,l,r): #0-indexed
        l+=2**(self.height-1)
        r+=2**(self.height-1)
        lf,rf=self.id,self.id
        while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
        return self.f(lf,rf)
n=int(input())
s=list(input())
q=int(input())
l=[]
for i in range(26):
    l.append(SegmentTree(s,chr(97+i),f=lambda x,y:x or y))
for _ in range(q):
    a,b,c=input().split()
    if a=="1":
        b=int(b)-1
        l[ord(s[b])-97].update(b,0)
        l[ord(c)-97].update(b,1)
        s[b]=c
    else:
        b,c=int(b)-1,int(c)
        count=0
        for i in range(26):
            if l[i].query(b,c):
                count+=1
        print(count)