import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    class Segtree:
        def __init__(self, A, ide_ele, initialize = True, segf = max):
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.ide_ele = ide_ele
            self.segf = segf
            if initialize:
                self.data = [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [ide_ele]*(2*self.N0)

        def update(self, k, x):
            k += self.N0
            self.data[k] = x
            while k > 0 :
                k = k >> 1
                self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])

        def query(self, l, r):
            L, R = l+self.N0, r+self.N0
            s = self.ide_ele
            t = self.ide_ele
            while L < R:
                if R & 1:
                    R -= 1
                    t = self.segf(self.data[R],t)
                if L & 1:
                    s = self.segf(s,self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return self.segf(s,t)

        # セグ木上で二分探索，[l,r)の範囲でcheck関数を満たす最小の値をとるところのindexを返す．
        # reverse=Trueなら最大値かな
        # ない時の返り値がNoneなことに注意
        def binsearch(self, l, r, check, reverse = False):
            L, R = l+self.N0, r+self.N0
            SL, SR = [], []
            while L < R:
                if R & 1:
                    R -= 1
                    SR.append(R)
                if L & 1:
                    SL.append(L)
                    L += 1
                L >>= 1
                R >>= 1

            if reverse:
                pre = self.ide_ele
                for idx in (SR + SL[::-1]):
                    if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                return idx - self.N0
            else:
                pre = self.ide_ele
                for idx in (SL + SR[::-1]):
                    if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                return idx - self.N0
    

    N=I()
    S=input()
    Q=I()
    
    A=[]
    for i in range(N):
        ii=ord(S[i])
        aaa=set([ii])
        A.append(aaa)
    
    seg=Segtree(A,set([]),segf=lambda a,b:a|b)
    
    for _ in range(Q):
        q=input().split()
        if q[0]=="1":
            i=int(q[1])-1
            c=q[2]
            seg.update(i,set([ord(c)]))
        else:
            l=int(q[1])
            r=int(q[2])
            ans=seg.query(l-1,r)
            print(len(ans))
    

main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def I(): return int(input()) I def MI(): return map(int, input().split()) MI def LI(): return list(map(int, input().split())) LI def main():
    class Segtree:
        def __init__(self, A, ide_ele, initialize = True, segf = max):
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.ide_ele = ide_ele
            self.segf = segf
            if initialize:
                self.data = [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [ide_ele]*(2*self.N0)

        def update(self, k, x):
            k += self.N0
            self.data[k] = x
            while k > 0 :
                k = k >> 1
                self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])

        def query(self, l, r):
            L, R = l+self.N0, r+self.N0
            s = self.ide_ele
            t = self.ide_ele
            while L < R:
                if R & 1:
                    R -= 1
                    t = self.segf(self.data[R],t)
                if L & 1:
                    s = self.segf(s,self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return self.segf(s,t)

        # セグ木上で二分探索，[l,r)の範囲でcheck関数を満たす最小の値をとるところのindexを返す．
        # reverse=Trueなら最大値かな
        # ない時の返り値がNoneなことに注意
        def binsearch(self, l, r, check, reverse = False):
            L, R = l+self.N0, r+self.N0
            SL, SR = [], []
            while L < R:
                if R & 1:
                    R -= 1
                    SR.append(R)
                if L & 1:
                    SL.append(L)
                    L += 1
                L >>= 1
                R >>= 1

            if reverse:
                pre = self.ide_ele
                for idx in (SR + SL[::-1]):
                    if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                return idx - self.N0
            else:
                pre = self.ide_ele
                for idx in (SL + SR[::-1]):
                    if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                return idx - self.N0
    

    N=I()
    S=input()
    Q=I()
    
    A=[]
    for i in range(N):
        ii=ord(S[i])
        aaa=set([ii])
        A.append(aaa)
    
    seg=Segtree(A,set([]),segf=lambda a,b:a|b)
    
    for _ in range(Q):
        q=input().split()
        if q[0]=="1":
            i=int(q[1])-1
            c=q[2]
            seg.update(i,set([ord(c)]))
        else:
            l=int(q[1])
            r=int(q[2])
            ans=seg.query(l-1,r)
            print(len(ans))
     main class Segtree:
        def __init__(self, A, ide_ele, initialize = True, segf = max):
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.ide_ele = ide_ele
            self.segf = segf
            if initialize:
                self.data = [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [ide_ele]*(2*self.N0)

        def update(self, k, x):
            k += self.N0
            self.data[k] = x
            while k > 0 :
                k = k >> 1
                self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])

        def query(self, l, r):
            L, R = l+self.N0, r+self.N0
            s = self.ide_ele
            t = self.ide_ele
            while L < R:
                if R & 1:
                    R -= 1
                    t = self.segf(self.data[R],t)
                if L & 1:
                    s = self.segf(s,self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return self.segf(s,t)

        # セグ木上で二分探索，[l,r)の範囲でcheck関数を満たす最小の値をとるところのindexを返す．
        # reverse=Trueなら最大値かな
        # ない時の返り値がNoneなことに注意
        def binsearch(self, l, r, check, reverse = False):
            L, R = l+self.N0, r+self.N0
            SL, SR = [], []
            while L < R:
                if R & 1:
                    R -= 1
                    SR.append(R)
                if L & 1:
                    SL.append(L)
                    L += 1
                L >>= 1
                R >>= 1

            if reverse:
                pre = self.ide_ele
                for idx in (SR + SL[::-1]):
                    if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                return idx - self.N0
            else:
                pre = self.ide_ele
                for idx in (SL + SR[::-1]):
                    if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                return idx - self.N0
    

     Segtree def __init__(self, A, ide_ele, initialize = True, segf = max):
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.ide_ele = ide_ele
            self.segf = segf
            if initialize:
                self.data = [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [ide_ele]*(2*self.N0)

         __init__ self.N = len(A) self.N self N len(A) len A self.N0 = 2**(self.N-1).bit_length() self.N0 self N0 2**(self.N-1).bit_length() 2 (self.N-1).bit_length() self.N-1).bit_length self.N-1 self.N self N 1 bit_length self.ide_ele = ide_ele self.ide_ele self ide_ele ide_ele self.segf = segf self.segf self segf segf if initialize:
                self.data = [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [ide_ele]*(2*self.N0)

         initialize self.data = [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N) self.data self data [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N) [ide_ele]*self.N0 + A [ide_ele]*self.N0 [ide_ele] ide_ele self.N0 self N0 A [ide_ele]*(self.N0 - self.N) [ide_ele] ide_ele self.N0 - self.N self.N0 self N0 self.N self N for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
             i range(self.N0-1, 0, -1) range self.N0-1 self.N0 self N0 1 0 -1 self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) self.data[i] self.data self data i self.segf(self.data[2*i], self.data[2*i+1]) self.segf self segf self.data[2*i] self.data self data 2*i 2 i self.data[2*i+1] self.data self data 2*i+1 2*i 2 i 1 self.data = [ide_ele]*(2*self.N0) self.data self data [ide_ele]*(2*self.N0) [ide_ele] ide_ele 2*self.N0 2 self.N0 self N0 self self A A ide_ele ide_ele initialize = True initialize True segf = max segf max def update(self, k, x):
            k += self.N0
            self.data[k] = x
            while k > 0 :
                k = k >> 1
                self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])

         update k += self.N0 k self.N0 self N0 self.data[k] = x self.data[k] self.data self data k x while k > 0 :
                k = k >> 1
                self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])

         k > 0 k 0 k = k >> 1 k k >> 1 k 1 self.data[k] = self.segf(self.data[2*k], self.data[2*k+1]) self.data[k] self.data self data k self.segf(self.data[2*k], self.data[2*k+1]) self.segf self segf self.data[2*k] self.data self data 2*k 2 k self.data[2*k+1] self.data self data 2*k+1 2*k 2 k 1 self self k k x x def query(self, l, r):
            L, R = l+self.N0, r+self.N0
            s = self.ide_ele
            t = self.ide_ele
            while L < R:
                if R & 1:
                    R -= 1
                    t = self.segf(self.data[R],t)
                if L & 1:
                    s = self.segf(s,self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return self.segf(s,t)

        # セグ木上で二分探索，[l,r)の範囲でcheck関数を満たす最小の値をとるところのindexを返す．
        # reverse=Trueなら最大値かな
        # ない時の返り値がNoneなことに注意
         query L, R = l+self.N0, r+self.N0 L l+self.N0 l self.N0 self N0 R r+self.N0 r self.N0 self N0 s = self.ide_ele s self.ide_ele self ide_ele t = self.ide_ele t self.ide_ele self ide_ele while L < R:
                if R & 1:
                    R -= 1
                    t = self.segf(self.data[R],t)
                if L & 1:
                    s = self.segf(s,self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
             L < R L R if R & 1:
                    R -= 1
                    t = self.segf(self.data[R],t)
                 R & 1 R 1 R -= 1 R 1 t = self.segf(self.data[R],t) t self.segf(self.data[R],t) self.segf self segf self.data[R] self.data self data R t if L & 1:
                    s = self.segf(s,self.data[L])
                    L += 1
                 L & 1 L 1 s = self.segf(s,self.data[L]) s self.segf(s,self.data[L]) self.segf self segf s self.data[L] self.data self data L L += 1 L 1 L >>= 1 L 1 R >>= 1 R 1 return self.segf(s,t) self.segf(s,t) self.segf self segf s t self self l l r r def binsearch(self, l, r, check, reverse = False):
            L, R = l+self.N0, r+self.N0
            SL, SR = [], []
            while L < R:
                if R & 1:
                    R -= 1
                    SR.append(R)
                if L & 1:
                    SL.append(L)
                    L += 1
                L >>= 1
                R >>= 1

            if reverse:
                pre = self.ide_ele
                for idx in (SR + SL[::-1]):
                    if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                return idx - self.N0
            else:
                pre = self.ide_ele
                for idx in (SL + SR[::-1]):
                    if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                return idx - self.N0
    

     binsearch L, R = l+self.N0, r+self.N0 L l+self.N0 l self.N0 self N0 R r+self.N0 r self.N0 self N0 SL, SR = [], [] SL [] SR [] while L < R:
                if R & 1:
                    R -= 1
                    SR.append(R)
                if L & 1:
                    SL.append(L)
                    L += 1
                L >>= 1
                R >>= 1

             L < R L R if R & 1:
                    R -= 1
                    SR.append(R)
                 R & 1 R 1 R -= 1 R 1 SR.append(R) SR.append SR append R if L & 1:
                    SL.append(L)
                    L += 1
                 L & 1 L 1 SL.append(L) SL.append SL append L L += 1 L 1 L >>= 1 L 1 R >>= 1 R 1 if reverse:
                pre = self.ide_ele
                for idx in (SR + SL[::-1]):
                    if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                return idx - self.N0
            else:
                pre = self.ide_ele
                for idx in (SL + SR[::-1]):
                    if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                return idx - self.N0
    

     reverse pre = self.ide_ele pre self.ide_ele self ide_ele for idx in (SR + SL[::-1]):
                    if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                else:
                    return None
                 idx SR + SL[::-1] SR SL[::-1] SL ::-1 -1 if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                 check(self.segf(self.data[idx], pre)) check self.segf(self.data[idx], pre) self.segf self segf self.data[idx] self.data self data idx pre break pre = self.segf(self.data[idx], pre) pre self.segf(self.data[idx], pre) self.segf self segf self.data[idx] self.data self data idx pre return None None while idx < self.N0:
                    if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                 idx < self.N0 idx self.N0 self N0 if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                 check(self.segf(self.data[2*idx+1], pre)) check self.segf(self.data[2*idx+1], pre) self.segf self segf self.data[2*idx+1] self.data self data 2*idx+1 2*idx 2 idx 1 pre idx = 2*idx + 1 idx 2*idx + 1 2*idx 2 idx 1 pre = self.segf(self.data[2*idx+1], pre) pre self.segf(self.data[2*idx+1], pre) self.segf self segf self.data[2*idx+1] self.data self data 2*idx+1 2*idx 2 idx 1 pre idx = 2*idx idx 2*idx 2 idx return idx - self.N0 idx - self.N0 idx self.N0 self N0 pre = self.ide_ele pre self.ide_ele self ide_ele for idx in (SL + SR[::-1]):
                    if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                else:
                    return None
                 idx SL + SR[::-1] SL SR[::-1] SR ::-1 -1 if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                 not check(self.segf(pre, self.data[idx])) check(self.segf(pre, self.data[idx])) check self.segf(pre, self.data[idx]) self.segf self segf pre self.data[idx] self.data self data idx pre = self.segf(pre, self.data[idx]) pre self.segf(pre, self.data[idx]) self.segf self segf pre self.data[idx] self.data self data idx break return None None while idx < self.N0:
                    if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                 idx < self.N0 idx self.N0 self N0 if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                 check(self.segf(pre, self.data[2*idx])) check self.segf(pre, self.data[2*idx]) self.segf self segf pre self.data[2*idx] self.data self data 2*idx 2 idx idx = 2*idx idx 2*idx 2 idx pre = self.segf(pre, self.data[2*idx]) pre self.segf(pre, self.data[2*idx]) self.segf self segf pre self.data[2*idx] self.data self data 2*idx 2 idx idx = 2*idx + 1 idx 2*idx + 1 2*idx 2 idx 1 return idx - self.N0 idx - self.N0 idx self.N0 self N0 self self l l r r check check reverse = False reverse False N=I() N I() I S=input() S input() input Q=I() Q I() I A=[] A [] for i in range(N):
        ii=ord(S[i])
        aaa=set([ii])
        A.append(aaa)
    
     i range(N) range N ii=ord(S[i]) ii ord(S[i]) ord S[i] S i aaa=set([ii]) aaa set([ii]) set [ii] ii A.append(aaa) A.append A append aaa seg=Segtree(A,set([]),segf=lambda a,b:a|b) seg Segtree(A,set([]),segf=lambda a,b:a|b) Segtree A set([]) set [] segf=lambda a,b:a|b segf lambda a,b:a|b a|b a b a b for _ in range(Q):
        q=input().split()
        if q[0]=="1":
            i=int(q[1])-1
            c=q[2]
            seg.update(i,set([ord(c)]))
        else:
            l=int(q[1])
            r=int(q[2])
            ans=seg.query(l-1,r)
            print(len(ans))
     _ range(Q) range Q q=input().split() q input().split() ().split () input split if q[0]=="1":
            i=int(q[1])-1
            c=q[2]
            seg.update(i,set([ord(c)]))
        else:
            l=int(q[1])
            r=int(q[2])
            ans=seg.query(l-1,r)
            print(len(ans))
     q[0]=="1" q[0] q 0 "1" i=int(q[1])-1 i int(q[1])-1 int(q[1]) int q[1] q 1 1 c=q[2] c q[2] q 2 seg.update(i,set([ord(c)])) seg.update seg update i set([ord(c)]) set [ord(c)] ord(c) ord c l=int(q[1]) l int(q[1]) int q[1] q 1 r=int(q[2]) r int(q[2]) int q[2] q 2 ans=seg.query(l-1,r) ans seg.query(l-1,r) seg.query seg query l-1 l 1 r print(len(ans)) print len(ans) len ans main() main def main():
    class Segtree:
        def __init__(self, A, ide_ele, initialize = True, segf = max):
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.ide_ele = ide_ele
            self.segf = segf
            if initialize:
                self.data = [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [ide_ele]*(2*self.N0)

        def update(self, k, x):
            k += self.N0
            self.data[k] = x
            while k > 0 :
                k = k >> 1
                self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])

        def query(self, l, r):
            L, R = l+self.N0, r+self.N0
            s = self.ide_ele
            t = self.ide_ele
            while L < R:
                if R & 1:
                    R -= 1
                    t = self.segf(self.data[R],t)
                if L & 1:
                    s = self.segf(s,self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return self.segf(s,t)

        # セグ木上で二分探索，[l,r)の範囲でcheck関数を満たす最小の値をとるところのindexを返す．
        # reverse=Trueなら最大値かな
        # ない時の返り値がNoneなことに注意
        def binsearch(self, l, r, check, reverse = False):
            L, R = l+self.N0, r+self.N0
            SL, SR = [], []
            while L < R:
                if R & 1:
                    R -= 1
                    SR.append(R)
                if L & 1:
                    SL.append(L)
                    L += 1
                L >>= 1
                R >>= 1

            if reverse:
                pre = self.ide_ele
                for idx in (SR + SL[::-1]):
                    if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                return idx - self.N0
            else:
                pre = self.ide_ele
                for idx in (SL + SR[::-1]):
                    if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                return idx - self.N0
    

    N=I()
    S=input()
    Q=I()
    
    A=[]
    for i in range(N):
        ii=ord(S[i])
        aaa=set([ii])
        A.append(aaa)
    
    seg=Segtree(A,set([]),segf=lambda a,b:a|b)
    
    for _ in range(Q):
        q=input().split()
        if q[0]=="1":
            i=int(q[1])-1
            c=q[2]
            seg.update(i,set([ord(c)]))
        else:
            l=int(q[1])
            r=int(q[2])
            ans=seg.query(l-1,r)
            print(len(ans))
     def main():
    class Segtree:
        def __init__(self, A, ide_ele, initialize = True, segf = max):
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.ide_ele = ide_ele
            self.segf = segf
            if initialize:
                self.data = [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [ide_ele]*(2*self.N0)

        def update(self, k, x):
            k += self.N0
            self.data[k] = x
            while k > 0 :
                k = k >> 1
                self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])

        def query(self, l, r):
            L, R = l+self.N0, r+self.N0
            s = self.ide_ele
            t = self.ide_ele
            while L < R:
                if R & 1:
                    R -= 1
                    t = self.segf(self.data[R],t)
                if L & 1:
                    s = self.segf(s,self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return self.segf(s,t)

        # セグ木上で二分探索，[l,r)の範囲でcheck関数を満たす最小の値をとるところのindexを返す．
        # reverse=Trueなら最大値かな
        # ない時の返り値がNoneなことに注意
        def binsearch(self, l, r, check, reverse = False):
            L, R = l+self.N0, r+self.N0
            SL, SR = [], []
            while L < R:
                if R & 1:
                    R -= 1
                    SR.append(R)
                if L & 1:
                    SL.append(L)
                    L += 1
                L >>= 1
                R >>= 1

            if reverse:
                pre = self.ide_ele
                for idx in (SR + SL[::-1]):
                    if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                return idx - self.N0
            else:
                pre = self.ide_ele
                for idx in (SL + SR[::-1]):
                    if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                return idx - self.N0
    

    N=I()
    S=input()
    Q=I()
    
    A=[]
    for i in range(N):
        ii=ord(S[i])
        aaa=set([ii])
        A.append(aaa)
    
    seg=Segtree(A,set([]),segf=lambda a,b:a|b)
    
    for _ in range(Q):
        q=input().split()
        if q[0]=="1":
            i=int(q[1])-1
            c=q[2]
            seg.update(i,set([ord(c)]))
        else:
            l=int(q[1])
            r=int(q[2])
            ans=seg.query(l-1,r)
            print(len(ans))
     main input = sys.stdin.readline sys.stdin.readline input def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI def I(): return int(input()) def I(): return int(input()) I def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    class Segtree:
        def __init__(self, A, ide_ele, initialize = True, segf = max):
            self.N = len(A)
            self.N0 = 2**(self.N-1).bit_length()
            self.ide_ele = ide_ele
            self.segf = segf
            if initialize:
                self.data = [ide_ele]*self.N0 + A + [ide_ele]*(self.N0 - self.N)
                for i in range(self.N0-1, 0, -1):
                    self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
            else:
                self.data = [ide_ele]*(2*self.N0)

        def update(self, k, x):
            k += self.N0
            self.data[k] = x
            while k > 0 :
                k = k >> 1
                self.data[k] = self.segf(self.data[2*k], self.data[2*k+1])

        def query(self, l, r):
            L, R = l+self.N0, r+self.N0
            s = self.ide_ele
            t = self.ide_ele
            while L < R:
                if R & 1:
                    R -= 1
                    t = self.segf(self.data[R],t)
                if L & 1:
                    s = self.segf(s,self.data[L])
                    L += 1
                L >>= 1
                R >>= 1
            return self.segf(s,t)

        # セグ木上で二分探索，[l,r)の範囲でcheck関数を満たす最小の値をとるところのindexを返す．
        # reverse=Trueなら最大値かな
        # ない時の返り値がNoneなことに注意
        def binsearch(self, l, r, check, reverse = False):
            L, R = l+self.N0, r+self.N0
            SL, SR = [], []
            while L < R:
                if R & 1:
                    R -= 1
                    SR.append(R)
                if L & 1:
                    SL.append(L)
                    L += 1
                L >>= 1
                R >>= 1

            if reverse:
                pre = self.ide_ele
                for idx in (SR + SL[::-1]):
                    if check(self.segf(self.data[idx], pre)):
                        break
                    else:
                        pre = self.segf(self.data[idx], pre)
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(self.data[2*idx+1], pre)):
                        idx = 2*idx + 1
                    else:
                        pre = self.segf(self.data[2*idx+1], pre)
                        idx = 2*idx
                return idx - self.N0
            else:
                pre = self.ide_ele
                for idx in (SL + SR[::-1]):
                    if not check(self.segf(pre, self.data[idx])):
                        pre = self.segf(pre, self.data[idx])
                    else:
                        break
                else:
                    return None
                while idx < self.N0:
                    if check(self.segf(pre, self.data[2*idx])):
                        idx = 2*idx
                    else:
                        pre = self.segf(pre, self.data[2*idx])
                        idx = 2*idx + 1
                return idx - self.N0
    

    N=I()
    S=input()
    Q=I()
    
    A=[]
    for i in range(N):
        ii=ord(S[i])
        aaa=set([ii])
        A.append(aaa)
    
    seg=Segtree(A,set([]),segf=lambda a,b:a|b)
    
    for _ in range(Q):
        q=input().split()
        if q[0]=="1":
            i=int(q[1])-1
            c=q[2]
            seg.update(i,set([ord(c)]))
        else:
            l=int(q[1])
            r=int(q[2])
            ans=seg.query(l-1,r)
            print(len(ans))
    

main()
