import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
class SegmentTree:
    #for pypy
    #treeは1-based-index
    __slots__=["size","func","default_val","tree","first_idx"]
    def __init__(self,initial_value_list,func,default_val,first_index=0):
        n=len(initial_value_list)
        self.first_idx=first_index
        self.size=1<<(n-1).bit_length()
        self.func=func#適用関数
        self.default_val=default_val#初期値
        self.tree=[default_val for i in range(2*self.size)]
        # 木の構築
        for i in range(n):
            d=[0]*26;d[initial_value_list[i]-97]=1
            self.tree[self.size+i]=d
        for i in range(self.size-1,0,-1):
            self.tree[i]=self.func(self.tree[2*i],self.tree[2*i+1])

    def update(self,k,x):
        k+=self.size-self.first_idx
        self.tree[k]=x
        while k>1:
            k>>=1
            self.tree[k]=self.func(self.tree[2*k],self.tree[2*k+1])
    def query(self, l, r):
        l+=self.size-self.first_idx
        r+=self.size-self.first_idx
        lret,rret=self.default_val,self.default_val
        while l<r:
            if l&1:
                lret=self.func(lret,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rret=self.func(self.tree[r], rret) # モノイドでは可換律は保証されていないので演算の方向に注意
            l>>=1
            r>>=1
        return self.func(lret, rret)
n=int(input())
def add(x,y):
    v=[0]*26
    for i in range(26):
        v[i]=x[i]+y[i]
    return v
seg=SegmentTree(list(input().rstrip()),add,[0]*26,1)
q=int(input())

for i in range(q):
    a,s,d=input().split()
    if int(a)==1:
        s=int(s)
        v=[0]*26;v[int.from_bytes(d,'big')-97]+=1
        seg.update(s,v)
        
    else:
        r=seg.query(1,int(s))
        l=seg.query(1,int(d)+1)
        
        ans=0
        for i in range(26):
            if l[i]>r[i]:ans+=1
        print(ans) import sys sys input=sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 class SegmentTree:
    #for pypy
    #treeは1-based-index
    __slots__=["size","func","default_val","tree","first_idx"]
    def __init__(self,initial_value_list,func,default_val,first_index=0):
        n=len(initial_value_list)
        self.first_idx=first_index
        self.size=1<<(n-1).bit_length()
        self.func=func#適用関数
        self.default_val=default_val#初期値
        self.tree=[default_val for i in range(2*self.size)]
        # 木の構築
        for i in range(n):
            d=[0]*26;d[initial_value_list[i]-97]=1
            self.tree[self.size+i]=d
        for i in range(self.size-1,0,-1):
            self.tree[i]=self.func(self.tree[2*i],self.tree[2*i+1])

    def update(self,k,x):
        k+=self.size-self.first_idx
        self.tree[k]=x
        while k>1:
            k>>=1
            self.tree[k]=self.func(self.tree[2*k],self.tree[2*k+1])
    def query(self, l, r):
        l+=self.size-self.first_idx
        r+=self.size-self.first_idx
        lret,rret=self.default_val,self.default_val
        while l<r:
            if l&1:
                lret=self.func(lret,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rret=self.func(self.tree[r], rret) # モノイドでは可換律は保証されていないので演算の方向に注意
            l>>=1
            r>>=1
        return self.func(lret, rret) SegmentTree __slots__=["size","func","default_val","tree","first_idx"] __slots__ ["size","func","default_val","tree","first_idx"] "size" "func" "default_val" "tree" "first_idx" def __init__(self,initial_value_list,func,default_val,first_index=0):
        n=len(initial_value_list)
        self.first_idx=first_index
        self.size=1<<(n-1).bit_length()
        self.func=func#適用関数
        self.default_val=default_val#初期値
        self.tree=[default_val for i in range(2*self.size)]
        # 木の構築
        for i in range(n):
            d=[0]*26;d[initial_value_list[i]-97]=1
            self.tree[self.size+i]=d
        for i in range(self.size-1,0,-1):
            self.tree[i]=self.func(self.tree[2*i],self.tree[2*i+1])

     __init__ n=len(initial_value_list) n len(initial_value_list) len initial_value_list self.first_idx=first_index self.first_idx self first_idx first_index self.size=1<<(n-1).bit_length() self.size self size 1<<(n-1).bit_length() 1 (n-1).bit_length() n-1).bit_length n-1 n 1 bit_length self.func=func self.func self func func self.default_val=default_val self.default_val self default_val default_val default_val for i in range(2*self.size) for i in range(2*self.size) i range(2*self.size) range 2*self.size 2 self.size self size for i in range(2*self.size) default_val self.tree=[default_val for i in range(2*self.size)] self.tree self tree [default_val for i in range(2*self.size)] for i in range(n):
            d=[0]*26;d[initial_value_list[i]-97]=1
            self.tree[self.size+i]=d
         i range(n) range n d=[0]*26 d [0]*26 [0] 0 26 d[initial_value_list[i]-97]=1 d[initial_value_list[i]-97] d initial_value_list[i]-97 initial_value_list[i] initial_value_list i 97 1 self.tree[self.size+i]=d self.tree[self.size+i] self.tree self tree self.size+i self.size self size i d for i in range(self.size-1,0,-1):
            self.tree[i]=self.func(self.tree[2*i],self.tree[2*i+1])

     i range(self.size-1,0,-1) range self.size-1 self.size self size 1 0 -1 self.tree[i]=self.func(self.tree[2*i],self.tree[2*i+1]) self.tree[i] self.tree self tree i self.func(self.tree[2*i],self.tree[2*i+1]) self.func self func 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 initial_value_list initial_value_list func func default_val default_val first_index=0 first_index 0 def update(self,k,x):
        k+=self.size-self.first_idx
        self.tree[k]=x
        while k>1:
            k>>=1
            self.tree[k]=self.func(self.tree[2*k],self.tree[2*k+1])
     update k+=self.size-self.first_idx k self.size-self.first_idx self.size self size self.first_idx self first_idx self.tree[k]=x self.tree[k] self.tree self tree k x while k>1:
            k>>=1
            self.tree[k]=self.func(self.tree[2*k],self.tree[2*k+1])
     k>1 k 1 k>>=1 k 1 self.tree[k]=self.func(self.tree[2*k],self.tree[2*k+1]) self.tree[k] self.tree self tree k self.func(self.tree[2*k],self.tree[2*k+1]) self.func self func self.tree[2*k] self.tree self tree 2*k 2 k self.tree[2*k+1] self.tree self tree 2*k+1 2*k 2 k 1 self self k k x x def query(self, l, r):
        l+=self.size-self.first_idx
        r+=self.size-self.first_idx
        lret,rret=self.default_val,self.default_val
        while l<r:
            if l&1:
                lret=self.func(lret,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rret=self.func(self.tree[r], rret) # モノイドでは可換律は保証されていないので演算の方向に注意
            l>>=1
            r>>=1
        return self.func(lret, rret) query l+=self.size-self.first_idx l self.size-self.first_idx self.size self size self.first_idx self first_idx r+=self.size-self.first_idx r self.size-self.first_idx self.size self size self.first_idx self first_idx lret,rret=self.default_val,self.default_val lret self.default_val self default_val rret self.default_val self default_val while l<r:
            if l&1:
                lret=self.func(lret,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rret=self.func(self.tree[r], rret) # モノイドでは可換律は保証されていないので演算の方向に注意
            l>>=1
            r>>=1
         l<r l r if l&1:
                lret=self.func(lret,self.tree[l])
                l+=1
             l&1 l 1 lret=self.func(lret,self.tree[l]) lret self.func(lret,self.tree[l]) self.func self func lret self.tree[l] self.tree self tree l l+=1 l 1 if r&1:
                r-=1
                rret=self.func(self.tree[r], rret) # モノイドでは可換律は保証されていないので演算の方向に注意
             r&1 r 1 r-=1 r 1 rret=self.func(self.tree[r], rret) rret self.func(self.tree[r], rret) self.func self func self.tree[r] self.tree self tree r rret l>>=1 l 1 r>>=1 r 1 return self.func(lret, rret) self.func(lret, rret) self.func self func lret rret self self l l r r n=int(input()) n int(input()) int input() input def add(x,y):
    v=[0]*26
    for i in range(26):
        v[i]=x[i]+y[i]
    return v add v=[0]*26 v [0]*26 [0] 0 26 for i in range(26):
        v[i]=x[i]+y[i]
     i range(26) range 26 v[i]=x[i]+y[i] v[i] v i x[i]+y[i] x[i] x i y[i] y i return v v x x y y seg=SegmentTree(list(input().rstrip()),add,[0]*26,1) seg SegmentTree(list(input().rstrip()),add,[0]*26,1) SegmentTree list(input().rstrip()) list input().rstrip() ().rstrip () input rstrip add [0]*26 [0] 0 26 1 q=int(input()) q int(input()) int input() input for i in range(q):
    a,s,d=input().split()
    if int(a)==1:
        s=int(s)
        v=[0]*26;v[int.from_bytes(d,'big')-97]+=1
        seg.update(s,v)
        
    else:
        r=seg.query(1,int(s))
        l=seg.query(1,int(d)+1)
        
        ans=0
        for i in range(26):
            if l[i]>r[i]:ans+=1
        print(ans) i range(q) range q a,s,d=input().split() a input().split() ().split () input split s d if int(a)==1:
        s=int(s)
        v=[0]*26;v[int.from_bytes(d,'big')-97]+=1
        seg.update(s,v)
        
    else:
        r=seg.query(1,int(s))
        l=seg.query(1,int(d)+1)
        
        ans=0
        for i in range(26):
            if l[i]>r[i]:ans+=1
        print(ans) int(a)==1 int(a) int a 1 s=int(s) s int(s) int s v=[0]*26 v [0]*26 [0] 0 26 v[int.from_bytes(d,'big')-97]+=1 v[int.from_bytes(d,'big')-97] v int.from_bytes(d,'big')-97 int.from_bytes(d,'big') int.from_bytes int from_bytes d 'big' 97 1 seg.update(s,v) seg.update seg update s v r=seg.query(1,int(s)) r seg.query(1,int(s)) seg.query seg query 1 int(s) int s l=seg.query(1,int(d)+1) l seg.query(1,int(d)+1) seg.query seg query 1 int(d)+1 int(d) int d 1 ans=0 ans 0 for i in range(26):
            if l[i]>r[i]:ans+=1
         i range(26) range 26 if l[i]>r[i]:ans+=1
         l[i]>r[i] l[i] l i r[i] r i print(ans) print ans v=[0]*26 [0]*26 v s,d=input().split() input().split() s q=int(input()) int(input()) q ans=0 0 ans seg=SegmentTree(list(input().rstrip()),add,[0]*26,1) SegmentTree(list(input().rstrip()),add,[0]*26,1) seg def add(x,y):
    v=[0]*26
    for i in range(26):
        v[i]=x[i]+y[i]
    return v def add(x,y):
    v=[0]*26
    for i in range(26):
        v[i]=x[i]+y[i]
    return v add a,s,d=input().split() input().split() a d=input().split() input().split() d class SegmentTree:
    #for pypy
    #treeは1-based-index
    __slots__=["size","func","default_val","tree","first_idx"]
    def __init__(self,initial_value_list,func,default_val,first_index=0):
        n=len(initial_value_list)
        self.first_idx=first_index
        self.size=1<<(n-1).bit_length()
        self.func=func#適用関数
        self.default_val=default_val#初期値
        self.tree=[default_val for i in range(2*self.size)]
        # 木の構築
        for i in range(n):
            d=[0]*26;d[initial_value_list[i]-97]=1
            self.tree[self.size+i]=d
        for i in range(self.size-1,0,-1):
            self.tree[i]=self.func(self.tree[2*i],self.tree[2*i+1])

    def update(self,k,x):
        k+=self.size-self.first_idx
        self.tree[k]=x
        while k>1:
            k>>=1
            self.tree[k]=self.func(self.tree[2*k],self.tree[2*k+1])
    def query(self, l, r):
        l+=self.size-self.first_idx
        r+=self.size-self.first_idx
        lret,rret=self.default_val,self.default_val
        while l<r:
            if l&1:
                lret=self.func(lret,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rret=self.func(self.tree[r], rret) # モノイドでは可換律は保証されていないので演算の方向に注意
            l>>=1
            r>>=1
        return self.func(lret, rret) class SegmentTree:
    #for pypy
    #treeは1-based-index
    __slots__=["size","func","default_val","tree","first_idx"]
    def __init__(self,initial_value_list,func,default_val,first_index=0):
        n=len(initial_value_list)
        self.first_idx=first_index
        self.size=1<<(n-1).bit_length()
        self.func=func#適用関数
        self.default_val=default_val#初期値
        self.tree=[default_val for i in range(2*self.size)]
        # 木の構築
        for i in range(n):
            d=[0]*26;d[initial_value_list[i]-97]=1
            self.tree[self.size+i]=d
        for i in range(self.size-1,0,-1):
            self.tree[i]=self.func(self.tree[2*i],self.tree[2*i+1])

    def update(self,k,x):
        k+=self.size-self.first_idx
        self.tree[k]=x
        while k>1:
            k>>=1
            self.tree[k]=self.func(self.tree[2*k],self.tree[2*k+1])
    def query(self, l, r):
        l+=self.size-self.first_idx
        r+=self.size-self.first_idx
        lret,rret=self.default_val,self.default_val
        while l<r:
            if l&1:
                lret=self.func(lret,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rret=self.func(self.tree[r], rret) # モノイドでは可換律は保証されていないので演算の方向に注意
            l>>=1
            r>>=1
        return self.func(lret, rret) SegmentTree n=int(input()) int(input()) n input=sys.stdin.buffer.readline sys.stdin.buffer.readline input r=seg.query(1,int(s)) seg.query(1,int(s)) r l=seg.query(1,int(d)+1) seg.query(1,int(d)+1) l s=int(s) int(s) s
import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)
class SegmentTree:
    #for pypy
    #treeは1-based-index
    __slots__=["size","func","default_val","tree","first_idx"]
    def __init__(self,initial_value_list,func,default_val,first_index=0):
        n=len(initial_value_list)
        self.first_idx=first_index
        self.size=1<<(n-1).bit_length()
        self.func=func#適用関数
        self.default_val=default_val#初期値
        self.tree=[default_val for i in range(2*self.size)]
        # 木の構築
        for i in range(n):
            d=[0]*26;d[initial_value_list[i]-97]=1
            self.tree[self.size+i]=d
        for i in range(self.size-1,0,-1):
            self.tree[i]=self.func(self.tree[2*i],self.tree[2*i+1])

    def update(self,k,x):
        k+=self.size-self.first_idx
        self.tree[k]=x
        while k>1:
            k>>=1
            self.tree[k]=self.func(self.tree[2*k],self.tree[2*k+1])
    def query(self, l, r):
        l+=self.size-self.first_idx
        r+=self.size-self.first_idx
        lret,rret=self.default_val,self.default_val
        while l<r:
            if l&1:
                lret=self.func(lret,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rret=self.func(self.tree[r], rret) # モノイドでは可換律は保証されていないので演算の方向に注意
            l>>=1
            r>>=1
        return self.func(lret, rret)
n=int(input())
def add(x,y):
    v=[0]*26
    for i in range(26):
        v[i]=x[i]+y[i]
    return v
seg=SegmentTree(list(input().rstrip()),add,[0]*26,1)
q=int(input())

for i in range(q):
    a,s,d=input().split()
    if int(a)==1:
        s=int(s)
        v=[0]*26;v[int.from_bytes(d,'big')-97]+=1
        seg.update(s,v)
        
    else:
        r=seg.query(1,int(s))
        l=seg.query(1,int(d)+1)
        
        ans=0
        for i in range(26):
            if l[i]>r[i]:ans+=1
        print(ans)
