import sys
read=sys.stdin.readline
class SEGTree:
    def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=1<<x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2]
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1|c2
    def get(self,a,b):
        return self.find(a,b,0,0,self.d)
def bitcnt(x):
    res=0
    while x>0:
        if x&1:
            res+=1
        x//=2
    return res

n=int(input())
s=input()
q=int(input())
seg=SEGTree(n)
for i in range(n):
    seg.update(i,ord(s[i])-97)
for i in range(q):
    q,x,y=read().rstrip().split()
    if q=='1':
        seg.update(int(x)-1,ord(y)-97)
    else:
        x,y=int(x)-1,int(y)
        bit=seg.get(x,y)
        print(bitcnt(bit)) import sys sys read=sys.stdin.readline read sys.stdin.readline sys.stdin sys stdin readline class SEGTree:
    def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=1<<x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2]
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1|c2
    def get(self,a,b):
        return self.find(a,b,0,0,self.d) SEGTree def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
     __init__ self.Unit=0 self.Unit self Unit 0 i=1 i 1 while(i<n):
            i*=2
         i<n i n i*=2 i 2 self.SEG=[self.Unit]*(2*i-1) self.SEG self SEG [self.Unit]*(2*i-1) [self.Unit] self.Unit self Unit 2*i-1 2*i 2 i 1 self.d=i self.d self d i self self n n def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=1<<x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2]
     update i+=self.d-1 i self.d-1 self.d self d 1 self.SEG[i]=1<<x self.SEG[i] self.SEG self SEG i 1<<x 1 x while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2]
     i>0 i 0 i=(i-1)//2 i (i-1)//2 i-1 i 1 2 self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2] self.SEG[i] self.SEG self SEG i self.SEG[i*2+1]|self.SEG[i*2+2] self.SEG[i*2+1] self.SEG self SEG i*2+1 i*2 i 2 1 self.SEG[i*2+2] self.SEG self SEG i*2+2 i*2 i 2 2 self self i i x x def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1|c2
     find if r<=a or b<=l:
            return self.Unit
         r<=a or b<=l r<=a r a b<=l b l return self.Unit self.Unit self Unit if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1|c2
     a<=l and r<=b a<=l a l r<=b r b return self.SEG[k] self.SEG[k] self.SEG self SEG k c1=self.find(a,b,2*k+1,l,(l+r)//2) c1 self.find(a,b,2*k+1,l,(l+r)//2) self.find self find a b 2*k+1 2*k 2 k 1 l (l+r)//2 l+r l r 2 c2=self.find(a,b,2*k+2,(l+r)//2,r) c2 self.find(a,b,2*k+2,(l+r)//2,r) self.find self find a b 2*k+2 2*k 2 k 2 (l+r)//2 l+r l r 2 r return c1|c2 c1|c2 c1 c2 self self a a b b k k l l r r def get(self,a,b):
        return self.find(a,b,0,0,self.d) get return self.find(a,b,0,0,self.d) self.find(a,b,0,0,self.d) self.find self find a b 0 0 self.d self d self self a a b b def bitcnt(x):
    res=0
    while x>0:
        if x&1:
            res+=1
        x//=2
    return res bitcnt res=0 res 0 while x>0:
        if x&1:
            res+=1
        x//=2
     x>0 x 0 if x&1:
            res+=1
         x&1 x 1 res+=1 res 1 x//=2 x 2 return res res x x n=int(input()) n int(input()) int input() input s=input() s input() input q=int(input()) q int(input()) int input() input seg=SEGTree(n) seg SEGTree(n) SEGTree n for i in range(n):
    seg.update(i,ord(s[i])-97) i range(n) range n seg.update(i,ord(s[i])-97) seg.update seg update i ord(s[i])-97 ord(s[i]) ord s[i] s i 97 for i in range(q):
    q,x,y=read().rstrip().split()
    if q=='1':
        seg.update(int(x)-1,ord(y)-97)
    else:
        x,y=int(x)-1,int(y)
        bit=seg.get(x,y)
        print(bitcnt(bit)) i range(q) range q q,x,y=read().rstrip().split() q read().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () read rstrip split x y if q=='1':
        seg.update(int(x)-1,ord(y)-97)
    else:
        x,y=int(x)-1,int(y)
        bit=seg.get(x,y)
        print(bitcnt(bit)) q=='1' q '1' seg.update(int(x)-1,ord(y)-97) seg.update seg update int(x)-1 int(x) int x 1 ord(y)-97 ord(y) ord y 97 x,y=int(x)-1,int(y) x int(x)-1 int(x) int x 1 y int(y) int y bit=seg.get(x,y) bit seg.get(x,y) seg.get seg get x y print(bitcnt(bit)) print bitcnt(bit) bitcnt bit s=input() input() s read=sys.stdin.readline sys.stdin.readline read x,y=read().rstrip().split() read().rstrip().split() x y=read().rstrip().split() read().rstrip().split() y n=int(input()) int(input()) n seg=SEGTree(n) SEGTree(n) seg x,y=int(x)-1,int(y) int(x)-1 x class SEGTree:
    def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=1<<x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2]
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1|c2
    def get(self,a,b):
        return self.find(a,b,0,0,self.d) class SEGTree:
    def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=1<<x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2]
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1|c2
    def get(self,a,b):
        return self.find(a,b,0,0,self.d) SEGTree def bitcnt(x):
    res=0
    while x>0:
        if x&1:
            res+=1
        x//=2
    return res def bitcnt(x):
    res=0
    while x>0:
        if x&1:
            res+=1
        x//=2
    return res bitcnt bit=seg.get(x,y) seg.get(x,y) bit q=int(input()) int(input()) q y=int(x)-1,int(y) int(y) y q,x,y=read().rstrip().split() read().rstrip().split() q
import sys
read=sys.stdin.readline
class SEGTree:
    def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=1<<x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2]
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1|c2
    def get(self,a,b):
        return self.find(a,b,0,0,self.d)
def bitcnt(x):
    res=0
    while x>0:
        if x&1:
            res+=1
        x//=2
    return res

n=int(input())
s=input()
q=int(input())
seg=SEGTree(n)
for i in range(n):
    seg.update(i,ord(s[i])-97)
for i in range(q):
    q,x,y=read().rstrip().split()
    if q=='1':
        seg.update(int(x)-1,ord(y)-97)
    else:
        x,y=int(x)-1,int(y)
        bit=seg.get(x,y)
        print(bitcnt(bit))