from collections import deque

class SegmentTree():
    def __init__(self,n,ide_ele,merge_func,init_val):
        self.n=n
        self.ide_ele=ide_ele
        self.merge_func=merge_func
        self.val=[0 for i in range(1<<n)]
        self.merge=[0 for i in range(1<<n)]
        self.parent=[-1 for i in range(1<<n)]
        deq=deque([1<<(n-1)])
        res=[]
        while deq:
            v=deq.popleft()
            res.append(v)
            if not v&1:
                gap=(v&-v)//2
                self.parent[v-gap]=v
                deq.append(v-gap)
                self.parent[v+gap]=v
                deq.append(v+gap)
        for v in res[::-1]:
            if v-1<len(init_val):
                self.val[v-1]=init_val[v-1]
            self.merge[v-1]=self.val[v-1]
            if not v&1:
                gap=(v&-v)//2
                self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])

    def update(self,id,x):
        self.val[id]=x
        pos=id+1
        while pos!=-1:
            if pos&1:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=(pos&-pos)//2
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
            pos=self.parent[pos]

    def lower_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        mini=nd-(nd&-nd)+1+k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>mini:
                id-=gap
            elif id==mini:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                return self.merge_func(*stack)
            else:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                id+=gap

    def upper_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        maxi=nd+(nd&-nd)-1-k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                id-=gap
            elif id==maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                return self.merge_func(*stack)
            else:
                id+=gap

    def query(self,l,r):
        id=1<<(self.n-1)
        while True:
            if id-1<l:
                id+=((id)&(-id))//2
            elif id-1>r:
                id-=((id)&(-id))//2
            else:
                res=self.val[id-1]
                if id%2:
                    return res
                gap=((id)&(-id))//2
                L,R=id-gap,id+gap
                #print(l,r,id,L,R)
                left=self.upper_kth_merge(L,id-1-l-1)
                right=self.lower_kth_merge(R,r-id)
                return self.merge_func(res,left,right)

ide_ele=0

def seg_func(*args):
    res=ide_ele
    for val in args:
        res|=val
    return res

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f

import sys

input=sys.stdin.readline

N=int(input())
S=input().rstrip()

init_val=[1<<(ord(S[i])-97) for i in range(N)]
test=SegmentTree(N.bit_length(),ide_ele,seg_func,init_val)

for _ in range(int(input())):
    t,l,r=input().split()
    t,l=int(t),int(l)
    if t==1:
        val=ord(r)-97
        test.update(l-1,1<<val)
    else:
        r=int(r)
        res=test.query(l-1,r-1)
        print(popcount(res)) from collections import deque class SegmentTree():
    def __init__(self,n,ide_ele,merge_func,init_val):
        self.n=n
        self.ide_ele=ide_ele
        self.merge_func=merge_func
        self.val=[0 for i in range(1<<n)]
        self.merge=[0 for i in range(1<<n)]
        self.parent=[-1 for i in range(1<<n)]
        deq=deque([1<<(n-1)])
        res=[]
        while deq:
            v=deq.popleft()
            res.append(v)
            if not v&1:
                gap=(v&-v)//2
                self.parent[v-gap]=v
                deq.append(v-gap)
                self.parent[v+gap]=v
                deq.append(v+gap)
        for v in res[::-1]:
            if v-1<len(init_val):
                self.val[v-1]=init_val[v-1]
            self.merge[v-1]=self.val[v-1]
            if not v&1:
                gap=(v&-v)//2
                self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])

    def update(self,id,x):
        self.val[id]=x
        pos=id+1
        while pos!=-1:
            if pos&1:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=(pos&-pos)//2
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
            pos=self.parent[pos]

    def lower_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        mini=nd-(nd&-nd)+1+k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>mini:
                id-=gap
            elif id==mini:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                return self.merge_func(*stack)
            else:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                id+=gap

    def upper_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        maxi=nd+(nd&-nd)-1-k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                id-=gap
            elif id==maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                return self.merge_func(*stack)
            else:
                id+=gap

    def query(self,l,r):
        id=1<<(self.n-1)
        while True:
            if id-1<l:
                id+=((id)&(-id))//2
            elif id-1>r:
                id-=((id)&(-id))//2
            else:
                res=self.val[id-1]
                if id%2:
                    return res
                gap=((id)&(-id))//2
                L,R=id-gap,id+gap
                #print(l,r,id,L,R)
                left=self.upper_kth_merge(L,id-1-l-1)
                right=self.lower_kth_merge(R,r-id)
                return self.merge_func(res,left,right) SegmentTree def __init__(self,n,ide_ele,merge_func,init_val):
        self.n=n
        self.ide_ele=ide_ele
        self.merge_func=merge_func
        self.val=[0 for i in range(1<<n)]
        self.merge=[0 for i in range(1<<n)]
        self.parent=[-1 for i in range(1<<n)]
        deq=deque([1<<(n-1)])
        res=[]
        while deq:
            v=deq.popleft()
            res.append(v)
            if not v&1:
                gap=(v&-v)//2
                self.parent[v-gap]=v
                deq.append(v-gap)
                self.parent[v+gap]=v
                deq.append(v+gap)
        for v in res[::-1]:
            if v-1<len(init_val):
                self.val[v-1]=init_val[v-1]
            self.merge[v-1]=self.val[v-1]
            if not v&1:
                gap=(v&-v)//2
                self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])

     __init__ self.n=n self.n self n n self.ide_ele=ide_ele self.ide_ele self ide_ele ide_ele self.merge_func=merge_func self.merge_func self merge_func merge_func 0 for i in range(1<<n) for i in range(1<<n) i range(1<<n) range 1<<n 1 n for i in range(1<<n) 0 self.val=[0 for i in range(1<<n)] self.val self val [0 for i in range(1<<n)] 0 for i in range(1<<n) for i in range(1<<n) i range(1<<n) range 1<<n 1 n for i in range(1<<n) 0 self.merge=[0 for i in range(1<<n)] self.merge self merge [0 for i in range(1<<n)] -1 for i in range(1<<n) for i in range(1<<n) i range(1<<n) range 1<<n 1 n for i in range(1<<n) -1 self.parent=[-1 for i in range(1<<n)] self.parent self parent [-1 for i in range(1<<n)] deq=deque([1<<(n-1)]) deq deque([1<<(n-1)]) deque [1<<(n-1)] 1<<(n-1) 1 n-1 n 1 res=[] res [] while deq:
            v=deq.popleft()
            res.append(v)
            if not v&1:
                gap=(v&-v)//2
                self.parent[v-gap]=v
                deq.append(v-gap)
                self.parent[v+gap]=v
                deq.append(v+gap)
         deq v=deq.popleft() v deq.popleft() deq.popleft deq popleft res.append(v) res.append res append v if not v&1:
                gap=(v&-v)//2
                self.parent[v-gap]=v
                deq.append(v-gap)
                self.parent[v+gap]=v
                deq.append(v+gap)
         not v&1 v&1 v 1 gap=(v&-v)//2 gap (v&-v)//2 v&-v v -v v 2 self.parent[v-gap]=v self.parent[v-gap] self.parent self parent v-gap v gap v deq.append(v-gap) deq.append deq append v-gap v gap self.parent[v+gap]=v self.parent[v+gap] self.parent self parent v+gap v gap v deq.append(v+gap) deq.append deq append v+gap v gap for v in res[::-1]:
            if v-1<len(init_val):
                self.val[v-1]=init_val[v-1]
            self.merge[v-1]=self.val[v-1]
            if not v&1:
                gap=(v&-v)//2
                self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])

     v res[::-1] res ::-1 -1 if v-1<len(init_val):
                self.val[v-1]=init_val[v-1]
             v-1<len(init_val) v-1 v 1 len(init_val) len init_val self.val[v-1]=init_val[v-1] self.val[v-1] self.val self val v-1 v 1 init_val[v-1] init_val v-1 v 1 self.merge[v-1]=self.val[v-1] self.merge[v-1] self.merge self merge v-1 v 1 self.val[v-1] self.val self val v-1 v 1 if not v&1:
                gap=(v&-v)//2
                self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])

     not v&1 v&1 v 1 gap=(v&-v)//2 gap (v&-v)//2 v&-v v -v v 2 self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1]) self.merge[v-1] self.merge self merge v-1 v 1 self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1]) self.merge_func self merge_func self.merge[v-1] self.merge self merge v-1 v 1 self.merge[v-gap-1] self.merge self merge v-gap-1 v-gap v gap 1 self.merge[v+gap-1] self.merge self merge v+gap-1 v+gap v gap 1 self self n n ide_ele ide_ele merge_func merge_func init_val init_val def update(self,id,x):
        self.val[id]=x
        pos=id+1
        while pos!=-1:
            if pos&1:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=(pos&-pos)//2
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
            pos=self.parent[pos]

     update self.val[id]=x self.val[id] self.val self val id x pos=id+1 pos id+1 id 1 while pos!=-1:
            if pos&1:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=(pos&-pos)//2
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
            pos=self.parent[pos]

     pos!=-1 pos -1 if pos&1:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=(pos&-pos)//2
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
             pos&1 pos 1 self.merge[pos-1]=self.val[pos-1] self.merge[pos-1] self.merge self merge pos-1 pos 1 self.val[pos-1] self.val self val pos-1 pos 1 gap=(pos&-pos)//2 gap (pos&-pos)//2 pos&-pos pos -pos pos 2 self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1]) self.merge[pos-1] self.merge self merge pos-1 pos 1 self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1]) self.merge_func self merge_func self.val[pos-1] self.val self val pos-1 pos 1 self.merge[pos+gap-1] self.merge self merge pos+gap-1 pos+gap pos gap 1 self.merge[pos-gap-1] self.merge self merge pos-gap-1 pos-gap pos gap 1 pos=self.parent[pos] pos self.parent[pos] self.parent self parent pos self self id id x x def lower_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        mini=nd-(nd&-nd)+1+k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>mini:
                id-=gap
            elif id==mini:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                return self.merge_func(*stack)
            else:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                id+=gap

     lower_kth_merge if k==-1:
            return self.ide_ele
         k==-1 k -1 return self.ide_ele self.ide_ele self ide_ele mini=nd-(nd&-nd)+1+k mini nd-(nd&-nd)+1+k nd-(nd&-nd)+1 nd-(nd&-nd) nd nd&-nd nd -nd nd 1 k id=nd id nd stack=[] stack [] while True:
            gap=(id&-id)//2
            if id>mini:
                id-=gap
            elif id==mini:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                return self.merge_func(*stack)
            else:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                id+=gap

     True gap=(id&-id)//2 gap (id&-id)//2 id&-id id -id id 2 if id>mini:
                id-=gap
            elif id==mini:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                return self.merge_func(*stack)
            else:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                id+=gap

     id>mini id mini id-=gap id gap elif id==mini:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                return self.merge_func(*stack)
             id==mini id mini stack.append(self.val[id-1]) stack.append stack append self.val[id-1] self.val self val id-1 id 1 stack.append(self.merge[id-gap-1]) stack.append stack append self.merge[id-gap-1] self.merge self merge id-gap-1 id-gap id gap 1 return self.merge_func(*stack) self.merge_func(*stack) self.merge_func self merge_func *stack stack stack.append(self.val[id-1]) stack.append stack append self.val[id-1] self.val self val id-1 id 1 stack.append(self.merge[id-gap-1]) stack.append stack append self.merge[id-gap-1] self.merge self merge id-gap-1 id-gap id gap 1 id+=gap id gap self self nd nd k k def upper_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        maxi=nd+(nd&-nd)-1-k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                id-=gap
            elif id==maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                return self.merge_func(*stack)
            else:
                id+=gap

     upper_kth_merge if k==-1:
            return self.ide_ele
         k==-1 k -1 return self.ide_ele self.ide_ele self ide_ele maxi=nd+(nd&-nd)-1-k maxi nd+(nd&-nd)-1-k nd+(nd&-nd)-1 nd+(nd&-nd) nd nd&-nd nd -nd nd 1 k id=nd id nd stack=[] stack [] while True:
            gap=(id&-id)//2
            if id>maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                id-=gap
            elif id==maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                return self.merge_func(*stack)
            else:
                id+=gap

     True gap=(id&-id)//2 gap (id&-id)//2 id&-id id -id id 2 if id>maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                id-=gap
            elif id==maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                return self.merge_func(*stack)
            else:
                id+=gap

     id>maxi id maxi stack.append(self.val[id-1]) stack.append stack append self.val[id-1] self.val self val id-1 id 1 stack.append(self.merge[id+gap-1]) stack.append stack append self.merge[id+gap-1] self.merge self merge id+gap-1 id+gap id gap 1 id-=gap id gap elif id==maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                return self.merge_func(*stack)
             id==maxi id maxi stack.append(self.val[id-1]) stack.append stack append self.val[id-1] self.val self val id-1 id 1 stack.append(self.merge[id+gap-1]) stack.append stack append self.merge[id+gap-1] self.merge self merge id+gap-1 id+gap id gap 1 return self.merge_func(*stack) self.merge_func(*stack) self.merge_func self merge_func *stack stack id+=gap id gap self self nd nd k k def query(self,l,r):
        id=1<<(self.n-1)
        while True:
            if id-1<l:
                id+=((id)&(-id))//2
            elif id-1>r:
                id-=((id)&(-id))//2
            else:
                res=self.val[id-1]
                if id%2:
                    return res
                gap=((id)&(-id))//2
                L,R=id-gap,id+gap
                #print(l,r,id,L,R)
                left=self.upper_kth_merge(L,id-1-l-1)
                right=self.lower_kth_merge(R,r-id)
                return self.merge_func(res,left,right) query id=1<<(self.n-1) id 1<<(self.n-1) 1 self.n-1 self.n self n 1 while True:
            if id-1<l:
                id+=((id)&(-id))//2
            elif id-1>r:
                id-=((id)&(-id))//2
            else:
                res=self.val[id-1]
                if id%2:
                    return res
                gap=((id)&(-id))//2
                L,R=id-gap,id+gap
                #print(l,r,id,L,R)
                left=self.upper_kth_merge(L,id-1-l-1)
                right=self.lower_kth_merge(R,r-id)
                return self.merge_func(res,left,right) True if id-1<l:
                id+=((id)&(-id))//2
            elif id-1>r:
                id-=((id)&(-id))//2
            else:
                res=self.val[id-1]
                if id%2:
                    return res
                gap=((id)&(-id))//2
                L,R=id-gap,id+gap
                #print(l,r,id,L,R)
                left=self.upper_kth_merge(L,id-1-l-1)
                right=self.lower_kth_merge(R,r-id)
                return self.merge_func(res,left,right) id-1<l id-1 id 1 l id+=((id)&(-id))//2 id ((id)&(-id))//2 (id)&(-id) id -id id 2 elif id-1>r:
                id-=((id)&(-id))//2
             id-1>r id-1 id 1 r id-=((id)&(-id))//2 id ((id)&(-id))//2 (id)&(-id) id -id id 2 res=self.val[id-1] res self.val[id-1] self.val self val id-1 id 1 if id%2:
                    return res
                 id%2 id 2 return res res gap=((id)&(-id))//2 gap ((id)&(-id))//2 (id)&(-id) id -id id 2 L,R=id-gap,id+gap L id-gap id gap R id+gap id gap left=self.upper_kth_merge(L,id-1-l-1) left self.upper_kth_merge(L,id-1-l-1) self.upper_kth_merge self upper_kth_merge L id-1-l-1 id-1-l id-1 id 1 l 1 right=self.lower_kth_merge(R,r-id) right self.lower_kth_merge(R,r-id) self.lower_kth_merge self lower_kth_merge R r-id r id return self.merge_func(res,left,right) self.merge_func(res,left,right) self.merge_func self merge_func res left right self self l l r r ide_ele=0 ide_ele 0 def seg_func(*args):
    res=ide_ele
    for val in args:
        res|=val
    return res seg_func res=ide_ele res ide_ele for val in args:
        res|=val
     val args res|=val res val return res res *args def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f popcount x = x - ((x >> 1) & 0x55555555) x x - ((x >> 1) & 0x55555555) x (x >> 1) & 0x55555555 x >> 1 x 1 0x55555555 x = (x & 0x33333333) + ((x >> 2) & 0x33333333) x (x & 0x33333333) + ((x >> 2) & 0x33333333) x & 0x33333333 x 0x33333333 (x >> 2) & 0x33333333 x >> 2 x 2 0x33333333 x = (x + (x >> 4)) & 0x0f0f0f0f x (x + (x >> 4)) & 0x0f0f0f0f x + (x >> 4) x x >> 4 x 4 0x0f0f0f0f x = x + (x >> 8) x x + (x >> 8) x x >> 8 x 8 x = x + (x >> 16) x x + (x >> 16) x x >> 16 x 16 return x & 0x0000007f x & 0x0000007f x 0x0000007f x x import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N=int(input()) N int(input()) int input() input S=input().rstrip() S input().rstrip() ().rstrip () input rstrip 1<<(ord(S[i])-97) for i in range(N) for i in range(N) i range(N) range N for i in range(N) 1<<(ord(S[i])-97) 1 ord(S[i])-97 ord(S[i]) ord S[i] S i 97 init_val=[1<<(ord(S[i])-97) for i in range(N)] init_val [1<<(ord(S[i])-97) for i in range(N)] test=SegmentTree(N.bit_length(),ide_ele,seg_func,init_val) test SegmentTree(N.bit_length(),ide_ele,seg_func,init_val) SegmentTree N.bit_length() N.bit_length N bit_length ide_ele seg_func init_val for _ in range(int(input())):
    t,l,r=input().split()
    t,l=int(t),int(l)
    if t==1:
        val=ord(r)-97
        test.update(l-1,1<<val)
    else:
        r=int(r)
        res=test.query(l-1,r-1)
        print(popcount(res)) _ range(int(input())) range int(input()) int input() input t,l,r=input().split() t input().split() ().split () input split l r t,l=int(t),int(l) t int(t) int t l int(l) int l if t==1:
        val=ord(r)-97
        test.update(l-1,1<<val)
    else:
        r=int(r)
        res=test.query(l-1,r-1)
        print(popcount(res)) t==1 t 1 val=ord(r)-97 val ord(r)-97 ord(r) ord r 97 test.update(l-1,1<<val) test.update test update l-1 l 1 1<<val 1 val r=int(r) r int(r) int r res=test.query(l-1,r-1) res test.query(l-1,r-1) test.query test query l-1 l 1 r-1 r 1 print(popcount(res)) print popcount(res) popcount res def seg_func(*args):
    res=ide_ele
    for val in args:
        res|=val
    return res def seg_func(*args):
    res=ide_ele
    for val in args:
        res|=val
    return res seg_func t,l,r=input().split() input().split() t val=ord(r)-97 ord(r)-97 val l,r=input().split() input().split() l ide_ele=0 0 ide_ele res=test.query(l-1,r-1) test.query(l-1,r-1) res t,l=int(t),int(l) int(t) t l=int(t),int(l) int(l) l init_val=[1<<(ord(S[i])-97) for i in range(N)] [1<<(ord(S[i])-97) for i in range(N)] init_val r=input().split() input().split() r def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f popcount class SegmentTree():
    def __init__(self,n,ide_ele,merge_func,init_val):
        self.n=n
        self.ide_ele=ide_ele
        self.merge_func=merge_func
        self.val=[0 for i in range(1<<n)]
        self.merge=[0 for i in range(1<<n)]
        self.parent=[-1 for i in range(1<<n)]
        deq=deque([1<<(n-1)])
        res=[]
        while deq:
            v=deq.popleft()
            res.append(v)
            if not v&1:
                gap=(v&-v)//2
                self.parent[v-gap]=v
                deq.append(v-gap)
                self.parent[v+gap]=v
                deq.append(v+gap)
        for v in res[::-1]:
            if v-1<len(init_val):
                self.val[v-1]=init_val[v-1]
            self.merge[v-1]=self.val[v-1]
            if not v&1:
                gap=(v&-v)//2
                self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])

    def update(self,id,x):
        self.val[id]=x
        pos=id+1
        while pos!=-1:
            if pos&1:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=(pos&-pos)//2
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
            pos=self.parent[pos]

    def lower_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        mini=nd-(nd&-nd)+1+k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>mini:
                id-=gap
            elif id==mini:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                return self.merge_func(*stack)
            else:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                id+=gap

    def upper_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        maxi=nd+(nd&-nd)-1-k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                id-=gap
            elif id==maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                return self.merge_func(*stack)
            else:
                id+=gap

    def query(self,l,r):
        id=1<<(self.n-1)
        while True:
            if id-1<l:
                id+=((id)&(-id))//2
            elif id-1>r:
                id-=((id)&(-id))//2
            else:
                res=self.val[id-1]
                if id%2:
                    return res
                gap=((id)&(-id))//2
                L,R=id-gap,id+gap
                #print(l,r,id,L,R)
                left=self.upper_kth_merge(L,id-1-l-1)
                right=self.lower_kth_merge(R,r-id)
                return self.merge_func(res,left,right) class SegmentTree():
    def __init__(self,n,ide_ele,merge_func,init_val):
        self.n=n
        self.ide_ele=ide_ele
        self.merge_func=merge_func
        self.val=[0 for i in range(1<<n)]
        self.merge=[0 for i in range(1<<n)]
        self.parent=[-1 for i in range(1<<n)]
        deq=deque([1<<(n-1)])
        res=[]
        while deq:
            v=deq.popleft()
            res.append(v)
            if not v&1:
                gap=(v&-v)//2
                self.parent[v-gap]=v
                deq.append(v-gap)
                self.parent[v+gap]=v
                deq.append(v+gap)
        for v in res[::-1]:
            if v-1<len(init_val):
                self.val[v-1]=init_val[v-1]
            self.merge[v-1]=self.val[v-1]
            if not v&1:
                gap=(v&-v)//2
                self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])

    def update(self,id,x):
        self.val[id]=x
        pos=id+1
        while pos!=-1:
            if pos&1:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=(pos&-pos)//2
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
            pos=self.parent[pos]

    def lower_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        mini=nd-(nd&-nd)+1+k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>mini:
                id-=gap
            elif id==mini:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                return self.merge_func(*stack)
            else:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                id+=gap

    def upper_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        maxi=nd+(nd&-nd)-1-k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                id-=gap
            elif id==maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                return self.merge_func(*stack)
            else:
                id+=gap

    def query(self,l,r):
        id=1<<(self.n-1)
        while True:
            if id-1<l:
                id+=((id)&(-id))//2
            elif id-1>r:
                id-=((id)&(-id))//2
            else:
                res=self.val[id-1]
                if id%2:
                    return res
                gap=((id)&(-id))//2
                L,R=id-gap,id+gap
                #print(l,r,id,L,R)
                left=self.upper_kth_merge(L,id-1-l-1)
                right=self.lower_kth_merge(R,r-id)
                return self.merge_func(res,left,right) SegmentTree input=sys.stdin.readline sys.stdin.readline input S=input().rstrip() input().rstrip() S N=int(input()) int(input()) N test=SegmentTree(N.bit_length(),ide_ele,seg_func,init_val) SegmentTree(N.bit_length(),ide_ele,seg_func,init_val) test r=int(r) int(r) r
from collections import deque

class SegmentTree():
    def __init__(self,n,ide_ele,merge_func,init_val):
        self.n=n
        self.ide_ele=ide_ele
        self.merge_func=merge_func
        self.val=[0 for i in range(1<<n)]
        self.merge=[0 for i in range(1<<n)]
        self.parent=[-1 for i in range(1<<n)]
        deq=deque([1<<(n-1)])
        res=[]
        while deq:
            v=deq.popleft()
            res.append(v)
            if not v&1:
                gap=(v&-v)//2
                self.parent[v-gap]=v
                deq.append(v-gap)
                self.parent[v+gap]=v
                deq.append(v+gap)
        for v in res[::-1]:
            if v-1<len(init_val):
                self.val[v-1]=init_val[v-1]
            self.merge[v-1]=self.val[v-1]
            if not v&1:
                gap=(v&-v)//2
                self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])

    def update(self,id,x):
        self.val[id]=x
        pos=id+1
        while pos!=-1:
            if pos&1:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=(pos&-pos)//2
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
            pos=self.parent[pos]

    def lower_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        mini=nd-(nd&-nd)+1+k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>mini:
                id-=gap
            elif id==mini:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                return self.merge_func(*stack)
            else:
                stack.append(self.val[id-1])
                stack.append(self.merge[id-gap-1])
                id+=gap

    def upper_kth_merge(self,nd,k):
        if k==-1:
            return self.ide_ele
        maxi=nd+(nd&-nd)-1-k
        id=nd
        stack=[]
        while True:
            gap=(id&-id)//2
            if id>maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                id-=gap
            elif id==maxi:
                stack.append(self.val[id-1])
                stack.append(self.merge[id+gap-1])
                return self.merge_func(*stack)
            else:
                id+=gap

    def query(self,l,r):
        id=1<<(self.n-1)
        while True:
            if id-1<l:
                id+=((id)&(-id))//2
            elif id-1>r:
                id-=((id)&(-id))//2
            else:
                res=self.val[id-1]
                if id%2:
                    return res
                gap=((id)&(-id))//2
                L,R=id-gap,id+gap
                #print(l,r,id,L,R)
                left=self.upper_kth_merge(L,id-1-l-1)
                right=self.lower_kth_merge(R,r-id)
                return self.merge_func(res,left,right)

ide_ele=0

def seg_func(*args):
    res=ide_ele
    for val in args:
        res|=val
    return res

def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f

import sys

input=sys.stdin.readline

N=int(input())
S=input().rstrip()

init_val=[1<<(ord(S[i])-97) for i in range(N)]
test=SegmentTree(N.bit_length(),ide_ele,seg_func,init_val)

for _ in range(int(input())):
    t,l,r=input().split()
    t,l=int(t),int(l)
    if t==1:
        val=ord(r)-97
        test.update(l-1,1<<val)
    else:
        r=int(r)
        res=test.query(l-1,r-1)
        print(popcount(res))