### BUGGY CODE ###

import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

class SegmentTree:
    def __init__(self, L, op, ide):
        self.op = op
        self.ide = ide
        self.sz = len(L)
        self.n = 1
        self.s = 1
        for i in range(1000):
            self.n *= 2
            self.s += 1
            if self.n >= self.sz:
                break
        self.node = [self.ide]*(2*self.n-1)

        #for i in range(self.sz):
        #    self.node[i+self.n-1] = L[i]

        #for i in range(self.n-2,-1,-1):
        #    self.node[i] = self.op(self.node[i*2+1],self.node[i*2+2])
    
    def add(self, a, x):
        k = a+self.n-1
        self.node[k] += x
        for i in range(1000):
            k = (k-1)//2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
            if k <= 0:
                break
    
    def substitute(self, a, x):
        k = a+self.n-1
        self.node[k] = x
        for i in range(1000):
            k = (k-1)//2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
            if k <= 0:
                break

    def get_one(self, a):
        k = a+self.n-1
        return self.node[k]
    
    def get(self, l, r):
        res = self.ide
        n = self.n
        if self.sz <= r or 0 > l:
            print('ERROR: the indice are wrong.')
            return False

        for i in range(self.s):
            count = 2**i-1
            a = (r+1)//n
            b = (l-1)//n
            if a-b == 3:
                res = self.op(self.node[count+b+1],res)
                res = self.op(self.node[count+b+2],res)
                right = a*n
                left = (b+1)*n-1
                break
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n
                left = (b+1)*n-1
                break
            n = n//2

        #left
        n1 = n//2        
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (left+1)//n1
            b = (l-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                left = (b+1)*n1-1                
            n1 = n1//2

        #right
        n1 = n//2        
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (r+1)//n1
            b = (right-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n1                
            n1 = n1//2
        return res
    


def main():
    #da=BIT([1,2,3])
    #print(da.bit)
    #print(da.sum(0))
    N = int(input())
    op = lambda a,b: a or b
    B = [SegmentTree([False]*N,op, False) for i in range(26)]

    S = list(input())

    for i in range(N):
        B[ord(S[i]) - ord("a")].add(i, True)

    Q = int(input())

    for i in range(Q):
        a,b,c = input().split()
        if a=="1":
            #print(B[0].bit)
            index = int(b)-1
            c = c
            if not S[index]==c:
                old = ord(S[index]) - ord("a")
                num = ord(c) - ord("a")
                B[num].add(index, True)
                B[old].substitute(index, False)
                S[index] = c
        else:
            #print(B[0].bit)
            #print(B[0].sum(1))
            l = int(b)-1
            r = int(c)-1
            ans = 0
            for j in range(26):
                if B[j].get(l,r):
                    ans+=1


            print(ans)

if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

class BIT:
            
    def __init__(self, L):
        self.N = len(L)
        self.bit = [0]*self.N
        #for i,l in enumerate(L):
        #    self.add(i,l)
        self.N0 = 1
        while self.N0*2 <= self.N:
            self.N0 *= 2

    def add(self, a, w):
        x = a + 1
        for i in range(1000):
            self.bit[x-1] += w
            x += x & -x
            if x > self.N:
                break

    def sum(self, a):
        x = a+1
        ret = 0
        for i in range(1000):
            ret += self.bit[x-1]
            x -= x & -x
            if x <= 0:
                break        
        return ret

    #you can use this function when the BIT has only non-negative values.
    def lower_bound(self, w):
        if w<=0:
            return 0
        x = 0
        k = self.N0
        while k>0:
            if x+k<=self.N:
                if self.bit[x+k-1]<w:
                    w-=self.bit[x+k-1]
                    x+=k
            k//=2
        return x+1


def main():
    #da=BIT([1,2,3])
    #print(da.bit)
    #print(da.sum(0))
    N = int(input())

    B = [BIT([0]*N) for i in range(26)]

    S = list(input())

    for i in range(N):
        B[ord(S[i]) - ord("a")].add(i, 1)

    Q = int(input())

    for i in range(Q):
        a,b,c = input().split()
        if a=="1":
            #print(B[0].bit)
            index = int(b)-1
            c = c
            if not S[index]==c:
                old = ord(S[index]) - ord("a")
                num = ord(c) - ord("a")
                B[num].add(index, 1)
                B[old].add(index, -1)
                S[index] = c
        else:
            #print(B[0].bit)
            #print(B[0].sum(1))
            l = int(b)-1
            r = int(c)-1
            ans = 0
            for j in range(26):
                if l==0:
                    if B[j].sum(r)>0:
                        ans+=1
                else:
                    if B[j].sum(r)-B[j].sum(l-1)>0:
                        ans+=1

            print(ans)

if __name__ == '__main__':
    main()