import sys
def input(): return sys.stdin.readline().rstrip()
def ctoi(c):
    return ord(c)-97
class BIT:
    def __init__(self, n):
        self.unit_sum=0 # to be set
        self.n=n
        self.dat=[0]*(n+1)#[1,n]
    def add(self,a,x): #a(1-)
        i=a
        while i<=self.n:
            self.dat[i]+=x
            i+=i&-i
    def sum(self,a,b=None): 
        if b!=None:
            return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
        res=self.unit_sum
        i=a
        while i>0:
            res+=self.dat[i]
            i-=i&-i
        return res  #Σ[1,a] a(1-)   
    def __str__(self):
        self.ans=[]
        for i in range(1,self.n):
            self.ans.append(self.sum(i,i+1))
        return ' '.join(map(str,self.ans))

def main():
    n=int(input())
    S=list(input())
    q=int(input())
    BIT_tree=[]
    for i in range(26):
        obj=BIT(n+1)
        BIT_tree.append(obj)
    for i in range(n):
        BIT_tree[ctoi(S[i])].add(i+1,1)
    for _ in range(q):
        query=input().split()
        if query[0]=="1":
            index,x=int(query[1])-1,query[2]
            BIT_tree[ctoi(S[index])].add(index+1,-1)
            BIT_tree[ctoi(x)].add(index+1,1)
            S[index]=x
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
            print(ans)

if __name__=='__main__':
    main() import sys sys def input(): return sys.stdin.readline().rstrip() input def ctoi(c):
    return ord(c)-97 ctoi return ord(c)-97 ord(c)-97 ord(c) ord c 97 c c class BIT:
    def __init__(self, n):
        self.unit_sum=0 # to be set
        self.n=n
        self.dat=[0]*(n+1)#[1,n]
    def add(self,a,x): #a(1-)
        i=a
        while i<=self.n:
            self.dat[i]+=x
            i+=i&-i
    def sum(self,a,b=None): 
        if b!=None:
            return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
        res=self.unit_sum
        i=a
        while i>0:
            res+=self.dat[i]
            i-=i&-i
        return res  #Σ[1,a] a(1-)   
    def __str__(self):
        self.ans=[]
        for i in range(1,self.n):
            self.ans.append(self.sum(i,i+1))
        return ' '.join(map(str,self.ans)) BIT def __init__(self, n):
        self.unit_sum=0 # to be set
        self.n=n
        self.dat=[0]*(n+1)#[1,n]
     __init__ self.unit_sum=0 self.unit_sum self unit_sum 0 self.n=n self.n self n n self.dat=[0]*(n+1) self.dat self dat [0]*(n+1) [0] 0 n+1 n 1 self self n n def add(self,a,x): #a(1-)
        i=a
        while i<=self.n:
            self.dat[i]+=x
            i+=i&-i
     add i=a i a while i<=self.n:
            self.dat[i]+=x
            i+=i&-i
     i<=self.n i self.n self n self.dat[i]+=x self.dat[i] self.dat self dat i x i+=i&-i i i&-i i -i i self self a a x x def sum(self,a,b=None): 
        if b!=None:
            return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
        res=self.unit_sum
        i=a
        while i>0:
            res+=self.dat[i]
            i-=i&-i
        return res  #Σ[1,a] a(1-)   
     sum if b!=None:
            return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
         b!=None b None return self.sum(b-1)-self.sum(a-1) self.sum(b-1)-self.sum(a-1) self.sum(b-1) self.sum self sum b-1 b 1 self.sum(a-1) self.sum self sum a-1 a 1 res=self.unit_sum res self.unit_sum self unit_sum i=a i a while i>0:
            res+=self.dat[i]
            i-=i&-i
         i>0 i 0 res+=self.dat[i] res self.dat[i] self.dat self dat i i-=i&-i i i&-i i -i i return res res self self a a b=None b None def __str__(self):
        self.ans=[]
        for i in range(1,self.n):
            self.ans.append(self.sum(i,i+1))
        return ' '.join(map(str,self.ans)) __str__ self.ans=[] self.ans self ans [] for i in range(1,self.n):
            self.ans.append(self.sum(i,i+1))
         i range(1,self.n) range 1 self.n self n self.ans.append(self.sum(i,i+1)) self.ans.append self.ans self ans append self.sum(i,i+1) self.sum self sum i i+1 i 1 return ' '.join(map(str,self.ans)) ' '.join(map(str,self.ans)) ' '.join ' ' join map(str,self.ans) map str self.ans self ans self self def main():
    n=int(input())
    S=list(input())
    q=int(input())
    BIT_tree=[]
    for i in range(26):
        obj=BIT(n+1)
        BIT_tree.append(obj)
    for i in range(n):
        BIT_tree[ctoi(S[i])].add(i+1,1)
    for _ in range(q):
        query=input().split()
        if query[0]=="1":
            index,x=int(query[1])-1,query[2]
            BIT_tree[ctoi(S[index])].add(index+1,-1)
            BIT_tree[ctoi(x)].add(index+1,1)
            S[index]=x
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
            print(ans) main 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 BIT_tree=[] BIT_tree [] for i in range(26):
        obj=BIT(n+1)
        BIT_tree.append(obj)
     i range(26) range 26 obj=BIT(n+1) obj BIT(n+1) BIT n+1 n 1 BIT_tree.append(obj) BIT_tree.append BIT_tree append obj for i in range(n):
        BIT_tree[ctoi(S[i])].add(i+1,1)
     i range(n) range n BIT_tree[ctoi(S[i])].add(i+1,1) [ctoi(S[i])].add [ctoi(S[i])] BIT_tree ctoi(S[i]) ctoi S[i] S i add i+1 i 1 1 for _ in range(q):
        query=input().split()
        if query[0]=="1":
            index,x=int(query[1])-1,query[2]
            BIT_tree[ctoi(S[index])].add(index+1,-1)
            BIT_tree[ctoi(x)].add(index+1,1)
            S[index]=x
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
            print(ans) _ range(q) range q query=input().split() query input().split() ().split () input split if query[0]=="1":
            index,x=int(query[1])-1,query[2]
            BIT_tree[ctoi(S[index])].add(index+1,-1)
            BIT_tree[ctoi(x)].add(index+1,1)
            S[index]=x
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
            print(ans) query[0]=="1" query[0] query 0 "1" index,x=int(query[1])-1,query[2] index int(query[1])-1 int(query[1]) int query[1] query 1 1 x query[2] query 2 BIT_tree[ctoi(S[index])].add(index+1,-1) [ctoi(S[index])].add [ctoi(S[index])] BIT_tree ctoi(S[index]) ctoi S[index] S index add index+1 index 1 -1 BIT_tree[ctoi(x)].add(index+1,1) [ctoi(x)].add [ctoi(x)] BIT_tree ctoi(x) ctoi x add index+1 index 1 1 S[index]=x S[index] S index x l,r=int(query[1])-1,int(query[2])-1 l int(query[1])-1 int(query[1]) int query[1] query 1 1 r int(query[2])-1 int(query[2]) int query[2] query 2 1 ans=0 ans 0 for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
             c range(26) range 26 if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
             BIT_tree[c].sum(l+1,r+2) [c].sum [c] BIT_tree c sum l+1 l 1 r+2 r 2 ans+=1 ans 1 print(ans) print ans if __name__=='__main__':
    main() __name__=='__main__' __name__ '__main__' main() main class BIT:
    def __init__(self, n):
        self.unit_sum=0 # to be set
        self.n=n
        self.dat=[0]*(n+1)#[1,n]
    def add(self,a,x): #a(1-)
        i=a
        while i<=self.n:
            self.dat[i]+=x
            i+=i&-i
    def sum(self,a,b=None): 
        if b!=None:
            return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
        res=self.unit_sum
        i=a
        while i>0:
            res+=self.dat[i]
            i-=i&-i
        return res  #Σ[1,a] a(1-)   
    def __str__(self):
        self.ans=[]
        for i in range(1,self.n):
            self.ans.append(self.sum(i,i+1))
        return ' '.join(map(str,self.ans)) class BIT:
    def __init__(self, n):
        self.unit_sum=0 # to be set
        self.n=n
        self.dat=[0]*(n+1)#[1,n]
    def add(self,a,x): #a(1-)
        i=a
        while i<=self.n:
            self.dat[i]+=x
            i+=i&-i
    def sum(self,a,b=None): 
        if b!=None:
            return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
        res=self.unit_sum
        i=a
        while i>0:
            res+=self.dat[i]
            i-=i&-i
        return res  #Σ[1,a] a(1-)   
    def __str__(self):
        self.ans=[]
        for i in range(1,self.n):
            self.ans.append(self.sum(i,i+1))
        return ' '.join(map(str,self.ans)) BIT def main():
    n=int(input())
    S=list(input())
    q=int(input())
    BIT_tree=[]
    for i in range(26):
        obj=BIT(n+1)
        BIT_tree.append(obj)
    for i in range(n):
        BIT_tree[ctoi(S[i])].add(i+1,1)
    for _ in range(q):
        query=input().split()
        if query[0]=="1":
            index,x=int(query[1])-1,query[2]
            BIT_tree[ctoi(S[index])].add(index+1,-1)
            BIT_tree[ctoi(x)].add(index+1,1)
            S[index]=x
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
            print(ans) def main():
    n=int(input())
    S=list(input())
    q=int(input())
    BIT_tree=[]
    for i in range(26):
        obj=BIT(n+1)
        BIT_tree.append(obj)
    for i in range(n):
        BIT_tree[ctoi(S[i])].add(i+1,1)
    for _ in range(q):
        query=input().split()
        if query[0]=="1":
            index,x=int(query[1])-1,query[2]
            BIT_tree[ctoi(S[index])].add(index+1,-1)
            BIT_tree[ctoi(x)].add(index+1,1)
            S[index]=x
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
            print(ans) main def input(): return sys.stdin.readline().rstrip() def input(): return sys.stdin.readline().rstrip() input def ctoi(c):
    return ord(c)-97 def ctoi(c):
    return ord(c)-97 ctoi
import sys
def input(): return sys.stdin.readline().rstrip()
def ctoi(c):
    return ord(c)-97
class BIT:
    def __init__(self, n):
        self.unit_sum=0 # to be set
        self.n=n
        self.dat=[0]*(n+1)#[1,n]
    def add(self,a,x): #a(1-)
        i=a
        while i<=self.n:
            self.dat[i]+=x
            i+=i&-i
    def sum(self,a,b=None): 
        if b!=None:
            return self.sum(b-1)-self.sum(a-1) #[a,b) a(1-),b(1-)
        res=self.unit_sum
        i=a
        while i>0:
            res+=self.dat[i]
            i-=i&-i
        return res  #Σ[1,a] a(1-)   
    def __str__(self):
        self.ans=[]
        for i in range(1,self.n):
            self.ans.append(self.sum(i,i+1))
        return ' '.join(map(str,self.ans))

def main():
    n=int(input())
    S=list(input())
    q=int(input())
    BIT_tree=[]
    for i in range(26):
        obj=BIT(n+1)
        BIT_tree.append(obj)
    for i in range(n):
        BIT_tree[ctoi(S[i])].add(i+1,1)
    for _ in range(q):
        query=input().split()
        if query[0]=="1":
            index,x=int(query[1])-1,query[2]
            BIT_tree[ctoi(S[index])].add(index+1,-1)
            BIT_tree[ctoi(x)].add(index+1,1)
            S[index]=x
        else:
            l,r=int(query[1])-1,int(query[2])-1
            ans=0
            for c in range(26):
                if BIT_tree[c].sum(l+1,r+2):
                    ans+=1
            print(ans)

if __name__=='__main__':
    main()