abc=list("abcdefghijklmnopqrstuvwxyz")

class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res



idx={}
for i in range(len(abc)):
    idx[abc[i]]=i
#print(idx)
N=int(input())
S=list(input())
Q=int(input())
L=[[0]*(N+1) for _ in range(26)]

def add(a,b):
    return a+b


for i in range(N):
    s=S[i]
    L[idx[s]][i+1]=1
    

segdict={}
for i in range(26):
    segdict[i]=SegmentTree(L[i],add,0)

for i in range(Q):
    query=input().split()
    num=int(query[0])

    if num==1:
        i=int(query[1])
        c=query[2]
        nows=S[i-1]
        segdict[idx[nows]].update(i,0)
        segdict[idx[c]].update(i,1)
        S[i-1]=c
    else:
        l=int(query[1])
        r=int(query[2])
        sub=0
        for j in range(26):
            x=segdict[j].query(l,r+1)
            if x>0:
                sub+=1
        print(sub) abc=list("abcdefghijklmnopqrstuvwxyz") abc list("abcdefghijklmnopqrstuvwxyz") list "abcdefghijklmnopqrstuvwxyz" class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res SegmentTree def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
     __init__ n = len(init_value) n len(init_value) len init_value self.N0 = 1 << (n - 1).bit_length() self.N0 self N0 1 << (n - 1).bit_length() 1 (n - 1).bit_length() n - 1).bit_length n - 1 n 1 bit_length self.ide_ele = ide_ele self.ide_ele self ide_ele ide_ele 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.segfunc = segfunc self.segfunc self segfunc segfunc for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
         i x enumerate(init_value) enumerate init_value self.data[i + self.N0 - 1] = x self.data[i + self.N0 - 1] self.data self data i + self.N0 - 1 i + self.N0 i self.N0 self N0 1 x for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
     i range(self.N0 - 2, -1, -1) range self.N0 - 2 self.N0 self N0 2 -1 -1 self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2]) self.data[i] self.data self data i self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2]) self.segfunc self segfunc self.data[2 * i + 1] self.data self data 2 * i + 1 2 * i 2 i 1 self.data[2 * i + 2] self.data self data 2 * i + 2 2 * i 2 i 2 self self init_value: list init_value segfunc segfunc ide_ele ide_ele def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
     update k += self.N0 - 1 k self.N0 - 1 self.N0 self N0 1 self.data[k] = x self.data[k] self.data self data k x while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
     k k = (k - 1) // 2 k (k - 1) // 2 k - 1 k 1 2 self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2]) self.data[k] self.data self data k self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2]) self.segfunc self segfunc self.data[k * 2 + 1] self.data self data k * 2 + 1 k * 2 k 2 1 self.data[k * 2 + 2] self.data self data k * 2 + 2 k * 2 k 2 2 self self k: int k x x def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res query L = left + self.N0 L left + self.N0 left self.N0 self N0 R = right + self.N0 R right + self.N0 right self.N0 self N0 res = self.ide_ele res self.ide_ele self ide_ele a, b = [], [] a [] b [] while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
         L < R L R if L & 1:
                a.append(L - 1)
                L += 1
             L & 1 L 1 a.append(L - 1) a.append a append L - 1 L 1 L += 1 L 1 if R & 1:
                R -= 1
                b.append(R - 1)
             R & 1 R 1 R -= 1 R 1 b.append(R - 1) b.append b append R - 1 R 1 L >>= 1 L 1 R >>= 1 R 1 for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
         i a + b[::-1] a b[::-1] b ::-1 -1 res = self.segfunc(res, self.data[i]) res self.segfunc(res, self.data[i]) self.segfunc self segfunc res self.data[i] self.data self data i return res res self self left: int left right: int right idx={} idx {} for i in range(len(abc)):
    idx[abc[i]]=i
#print(idx) i range(len(abc)) range len(abc) len abc idx[abc[i]]=i idx[abc[i]] idx abc[i] abc i i N=int(input()) N int(input()) int input() input S=list(input()) S list(input()) list input() input Q=int(input()) Q int(input()) int input() input [0]*(N+1) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0]*(N+1) [0] 0 N+1 N 1 L=[[0]*(N+1) for _ in range(26)] L [[0]*(N+1) for _ in range(26)] def add(a,b):
    return a+b add return a+b a+b a b a a b b for i in range(N):
    s=S[i]
    L[idx[s]][i+1]=1
     i range(N) range N s=S[i] s S[i] S i L[idx[s]][i+1]=1 L[idx[s]][i+1] [idx[s]] L idx[s] idx s i+1 i 1 1 segdict={} segdict {} for i in range(26):
    segdict[i]=SegmentTree(L[i],add,0) i range(26) range 26 segdict[i]=SegmentTree(L[i],add,0) segdict[i] segdict i SegmentTree(L[i],add,0) SegmentTree L[i] L i add 0 for i in range(Q):
    query=input().split()
    num=int(query[0])

    if num==1:
        i=int(query[1])
        c=query[2]
        nows=S[i-1]
        segdict[idx[nows]].update(i,0)
        segdict[idx[c]].update(i,1)
        S[i-1]=c
    else:
        l=int(query[1])
        r=int(query[2])
        sub=0
        for j in range(26):
            x=segdict[j].query(l,r+1)
            if x>0:
                sub+=1
        print(sub) i range(Q) range Q query=input().split() query input().split() ().split () input split num=int(query[0]) num int(query[0]) int query[0] query 0 if num==1:
        i=int(query[1])
        c=query[2]
        nows=S[i-1]
        segdict[idx[nows]].update(i,0)
        segdict[idx[c]].update(i,1)
        S[i-1]=c
    else:
        l=int(query[1])
        r=int(query[2])
        sub=0
        for j in range(26):
            x=segdict[j].query(l,r+1)
            if x>0:
                sub+=1
        print(sub) num==1 num 1 i=int(query[1]) i int(query[1]) int query[1] query 1 c=query[2] c query[2] query 2 nows=S[i-1] nows S[i-1] S i-1 i 1 segdict[idx[nows]].update(i,0) [idx[nows]].update [idx[nows]] segdict idx[nows] idx nows update i 0 segdict[idx[c]].update(i,1) [idx[c]].update [idx[c]] segdict idx[c] idx c update i 1 S[i-1]=c S[i-1] S i-1 i 1 c l=int(query[1]) l int(query[1]) int query[1] query 1 r=int(query[2]) r int(query[2]) int query[2] query 2 sub=0 sub 0 for j in range(26):
            x=segdict[j].query(l,r+1)
            if x>0:
                sub+=1
         j range(26) range 26 x=segdict[j].query(l,r+1) x segdict[j].query(l,r+1) [j].query [j] segdict j query l r+1 r 1 if x>0:
                sub+=1
         x>0 x 0 sub+=1 sub 1 print(sub) print sub sub=0 0 sub c=query[2] query[2] c r=int(query[2]) int(query[2]) r S=list(input()) list(input()) S num=int(query[0]) int(query[0]) num s=S[i] S[i] s Q=int(input()) int(input()) Q query=input().split() input().split() query class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res SegmentTree x=segdict[j].query(l,r+1) segdict[j].query(l,r+1) x idx={} {} idx nows=S[i-1] S[i-1] nows L=[[0]*(N+1) for _ in range(26)] [[0]*(N+1) for _ in range(26)] L N=int(input()) int(input()) N abc=list("abcdefghijklmnopqrstuvwxyz") list("abcdefghijklmnopqrstuvwxyz") abc def add(a,b):
    return a+b def add(a,b):
    return a+b add segdict={} {} segdict l=int(query[1]) int(query[1]) l i=int(query[1]) int(query[1]) i sub+=1 1 sub
abc=list("abcdefghijklmnopqrstuvwxyz")

class SegmentTree:
    def __init__(self, init_value: list, segfunc, ide_ele):
        n = len(init_value)
        self.N0 = 1 << (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i, x in enumerate(init_value):
            self.data[i + self.N0 - 1] = x
        for i in range(self.N0 - 2, -1, -1):
            self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2])
    
    def update(self, k: int, x):
        k += self.N0 - 1
        ############################
        self.data[k] = x
        ###########################
        while k:
            k = (k - 1) // 2
            self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2])
    
    def query(self, left: int, right: int):
        L = left + self.N0
        R = right + self.N0
        res = self.ide_ele
        ##########################
        a, b = [], []
        while L < R:
            if L & 1:
                a.append(L - 1)
                L += 1
            if R & 1:
                R -= 1
                b.append(R - 1)
            L >>= 1
            R >>= 1
        for i in a + b[::-1]:
            res = self.segfunc(res, self.data[i])
        ##########################
        return res



idx={}
for i in range(len(abc)):
    idx[abc[i]]=i
#print(idx)
N=int(input())
S=list(input())
Q=int(input())
L=[[0]*(N+1) for _ in range(26)]

def add(a,b):
    return a+b


for i in range(N):
    s=S[i]
    L[idx[s]][i+1]=1
    

segdict={}
for i in range(26):
    segdict[i]=SegmentTree(L[i],add,0)

for i in range(Q):
    query=input().split()
    num=int(query[0])

    if num==1:
        i=int(query[1])
        c=query[2]
        nows=S[i-1]
        segdict[idx[nows]].update(i,0)
        segdict[idx[c]].update(i,1)
        S[i-1]=c
    else:
        l=int(query[1])
        r=int(query[2])
        sub=0
        for j in range(26):
            x=segdict[j].query(l,r+1)
            if x>0:
                sub+=1
        print(sub)