class SegmentTree():
    def __init__(self,n,ide_ele,merge_func):
        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)]

    def update(self,id,x):
        stack=[]
        pos=1<<(self.n-1)
        while pos-1!=id:
            stack.append(pos)
            if pos-1>id:
                pos-=((pos)&(-pos))//2
            else:
                pos+=((pos)&(-pos))//2

        stack.append(pos)
        self.val[pos-1]=x
        for pos in stack[::-1]:
            if pos%2:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=((pos)&(-pos))//2
                r=pos+gap
                l=pos-gap
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1])

    def cnt(self,k):
        lsb=(k)&(-k)
        return (lsb<<1)-1

    def lower_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(l)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    id=r
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                else:
                    id=l
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    def upper_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(r)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    id=l
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                else:
                    id=r
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    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()

test=SegmentTree(19,ide_ele,seg_func)
for i in range(N):
    val=ord(S[i])-97
    test.update(i,1<<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)) class SegmentTree():
    def __init__(self,n,ide_ele,merge_func):
        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)]

    def update(self,id,x):
        stack=[]
        pos=1<<(self.n-1)
        while pos-1!=id:
            stack.append(pos)
            if pos-1>id:
                pos-=((pos)&(-pos))//2
            else:
                pos+=((pos)&(-pos))//2

        stack.append(pos)
        self.val[pos-1]=x
        for pos in stack[::-1]:
            if pos%2:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=((pos)&(-pos))//2
                r=pos+gap
                l=pos-gap
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1])

    def cnt(self,k):
        lsb=(k)&(-k)
        return (lsb<<1)-1

    def lower_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(l)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    id=r
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                else:
                    id=l
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    def upper_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(r)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    id=l
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                else:
                    id=r
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    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):
        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)]

     __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)] self self n n ide_ele ide_ele merge_func merge_func def update(self,id,x):
        stack=[]
        pos=1<<(self.n-1)
        while pos-1!=id:
            stack.append(pos)
            if pos-1>id:
                pos-=((pos)&(-pos))//2
            else:
                pos+=((pos)&(-pos))//2

        stack.append(pos)
        self.val[pos-1]=x
        for pos in stack[::-1]:
            if pos%2:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=((pos)&(-pos))//2
                r=pos+gap
                l=pos-gap
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1])

     update stack=[] stack [] pos=1<<(self.n-1) pos 1<<(self.n-1) 1 self.n-1 self.n self n 1 while pos-1!=id:
            stack.append(pos)
            if pos-1>id:
                pos-=((pos)&(-pos))//2
            else:
                pos+=((pos)&(-pos))//2

         pos-1!=id pos-1 pos 1 id stack.append(pos) stack.append stack append pos if pos-1>id:
                pos-=((pos)&(-pos))//2
            else:
                pos+=((pos)&(-pos))//2

         pos-1>id pos-1 pos 1 id pos-=((pos)&(-pos))//2 pos ((pos)&(-pos))//2 (pos)&(-pos) pos -pos pos 2 pos+=((pos)&(-pos))//2 pos ((pos)&(-pos))//2 (pos)&(-pos) pos -pos pos 2 stack.append(pos) stack.append stack append pos self.val[pos-1]=x self.val[pos-1] self.val self val pos-1 pos 1 x for pos in stack[::-1]:
            if pos%2:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=((pos)&(-pos))//2
                r=pos+gap
                l=pos-gap
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1])

     pos stack[::-1] stack ::-1 -1 if pos%2:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=((pos)&(-pos))//2
                r=pos+gap
                l=pos-gap
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1])

     pos%2 pos 2 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 r=pos+gap r pos+gap pos gap l=pos-gap l pos-gap pos gap self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1]) self.merge[pos-1] self.merge self merge pos-1 pos 1 self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1]) self.merge_func self merge_func self.val[pos-1] self.val self val pos-1 pos 1 self.merge[r-1] self.merge self merge r-1 r 1 self.merge[l-1] self.merge self merge l-1 l 1 self self id id x x def cnt(self,k):
        lsb=(k)&(-k)
        return (lsb<<1)-1

     cnt lsb=(k)&(-k) lsb (k)&(-k) k -k k return (lsb<<1)-1 (lsb<<1)-1 lsb<<1 lsb 1 1 self self k k def lower_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(l)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    id=r
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                else:
                    id=l
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

     lower_kth_merge res=self.ide_ele res self.ide_ele self ide_ele id=nd id nd if k==-1:
            return res
         k==-1 k -1 return res res while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(l)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    id=r
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                else:
                    id=l
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

     True if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(l)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    id=r
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                else:
                    id=l
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

     not id%2 id%2 id 2 gap=((id)&(-id))//2 gap ((id)&(-id))//2 (id)&(-id) id -id id 2 l=id-gap l id-gap id gap r=id+gap r id+gap id gap cnt=self.cnt(l) cnt self.cnt(l) self.cnt self cnt l if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    id=r
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                else:
                    id=l
             cnt<k cnt k k-=cnt+1 k cnt+1 cnt 1 res=self.merge_func(res,self.val[id-1],self.merge[l-1]) res self.merge_func(res,self.val[id-1],self.merge[l-1]) self.merge_func self merge_func res self.val[id-1] self.val self val id-1 id 1 self.merge[l-1] self.merge self merge l-1 l 1 id=r id r elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                 cnt==k cnt k res=self.merge_func(res,self.val[id-1],self.merge[l-1]) res self.merge_func(res,self.val[id-1],self.merge[l-1]) self.merge_func self merge_func res self.val[id-1] self.val self val id-1 id 1 self.merge[l-1] self.merge self merge l-1 l 1 return res res id=l id l res=self.merge_func(res,self.val[id-1]) res self.merge_func(res,self.val[id-1]) self.merge_func self merge_func res self.val[id-1] self.val self val id-1 id 1 return res res self self nd nd k k def upper_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(r)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    id=l
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                else:
                    id=r
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

     upper_kth_merge res=self.ide_ele res self.ide_ele self ide_ele id=nd id nd if k==-1:
            return res
         k==-1 k -1 return res res while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(r)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    id=l
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                else:
                    id=r
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

     True if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(r)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    id=l
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                else:
                    id=r
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

     not id%2 id%2 id 2 gap=((id)&(-id))//2 gap ((id)&(-id))//2 (id)&(-id) id -id id 2 l=id-gap l id-gap id gap r=id+gap r id+gap id gap cnt=self.cnt(r) cnt self.cnt(r) self.cnt self cnt r if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    id=l
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                else:
                    id=r
             cnt<k cnt k k-=cnt+1 k cnt+1 cnt 1 res=self.merge_func(res,self.val[id-1],self.merge[r-1]) res self.merge_func(res,self.val[id-1],self.merge[r-1]) self.merge_func self merge_func res self.val[id-1] self.val self val id-1 id 1 self.merge[r-1] self.merge self merge r-1 r 1 id=l id l elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                 cnt==k cnt k res=self.merge_func(res,self.val[id-1],self.merge[r-1]) res self.merge_func(res,self.val[id-1],self.merge[r-1]) self.merge_func self merge_func res self.val[id-1] self.val self val id-1 id 1 self.merge[r-1] self.merge self merge r-1 r 1 return res res id=r id r res=self.merge_func(res,self.val[id-1]) res self.merge_func(res,self.val[id-1]) self.merge_func self merge_func res self.val[id-1] self.val self val id-1 id 1 return res res 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 test=SegmentTree(19,ide_ele,seg_func) test SegmentTree(19,ide_ele,seg_func) SegmentTree 19 ide_ele seg_func for i in range(N):
    val=ord(S[i])-97
    test.update(i,1<<val) i range(N) range N val=ord(S[i])-97 val ord(S[i])-97 ord(S[i]) ord S[i] S i 97 test.update(i,1<<val) test.update test update i 1<<val 1 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 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 t,l=int(t),int(l) int(t) t ide_ele=0 0 ide_ele test=SegmentTree(19,ide_ele,seg_func) SegmentTree(19,ide_ele,seg_func) test S=input().rstrip() input().rstrip() S t,l,r=input().split() input().split() t l=int(t),int(l) int(l) l val=ord(r)-97 ord(r)-97 val r=int(r) int(r) r class SegmentTree():
    def __init__(self,n,ide_ele,merge_func):
        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)]

    def update(self,id,x):
        stack=[]
        pos=1<<(self.n-1)
        while pos-1!=id:
            stack.append(pos)
            if pos-1>id:
                pos-=((pos)&(-pos))//2
            else:
                pos+=((pos)&(-pos))//2

        stack.append(pos)
        self.val[pos-1]=x
        for pos in stack[::-1]:
            if pos%2:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=((pos)&(-pos))//2
                r=pos+gap
                l=pos-gap
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1])

    def cnt(self,k):
        lsb=(k)&(-k)
        return (lsb<<1)-1

    def lower_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(l)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    id=r
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                else:
                    id=l
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    def upper_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(r)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    id=l
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                else:
                    id=r
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    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):
        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)]

    def update(self,id,x):
        stack=[]
        pos=1<<(self.n-1)
        while pos-1!=id:
            stack.append(pos)
            if pos-1>id:
                pos-=((pos)&(-pos))//2
            else:
                pos+=((pos)&(-pos))//2

        stack.append(pos)
        self.val[pos-1]=x
        for pos in stack[::-1]:
            if pos%2:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=((pos)&(-pos))//2
                r=pos+gap
                l=pos-gap
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1])

    def cnt(self,k):
        lsb=(k)&(-k)
        return (lsb<<1)-1

    def lower_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(l)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    id=r
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                else:
                    id=l
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    def upper_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(r)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    id=l
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                else:
                    id=r
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    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 l,r=input().split() input().split() l res=test.query(l-1,r-1) test.query(l-1,r-1) 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 r=input().split() input().split() r input=sys.stdin.readline sys.stdin.readline input val=ord(S[i])-97 ord(S[i])-97 val N=int(input()) int(input()) N
class SegmentTree():
    def __init__(self,n,ide_ele,merge_func):
        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)]

    def update(self,id,x):
        stack=[]
        pos=1<<(self.n-1)
        while pos-1!=id:
            stack.append(pos)
            if pos-1>id:
                pos-=((pos)&(-pos))//2
            else:
                pos+=((pos)&(-pos))//2

        stack.append(pos)
        self.val[pos-1]=x
        for pos in stack[::-1]:
            if pos%2:
                self.merge[pos-1]=self.val[pos-1]
            else:
                gap=((pos)&(-pos))//2
                r=pos+gap
                l=pos-gap
                self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[r-1],self.merge[l-1])

    def cnt(self,k):
        lsb=(k)&(-k)
        return (lsb<<1)-1

    def lower_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(l)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    id=r
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[l-1])
                    return res
                else:
                    id=l
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    def upper_kth_merge(self,nd,k):
        res=self.ide_ele
        id=nd
        if k==-1:
            return res
        while True:
            if not id%2:
                gap=((id)&(-id))//2
                l=id-gap
                r=id+gap
                cnt=self.cnt(r)
                if cnt<k:
                    k-=cnt+1
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    id=l
                elif cnt==k:
                    res=self.merge_func(res,self.val[id-1],self.merge[r-1])
                    return res
                else:
                    id=r
            else:
                res=self.merge_func(res,self.val[id-1])
                return res

    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()

test=SegmentTree(19,ide_ele,seg_func)
for i in range(N):
    val=ord(S[i])-97
    test.update(i,1<<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))