class SegTree():
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.func = function
        self.basement = basement
        self.seg = [basement]*(2**(self.K+1))
        X=2**self.K
        for i,v in enumerate(lists):
            self.seg[i+X-1] = v

        for i in range(2*X-2, 0, -2):
            self.seg[(i-1)>>1] = self.func(self.seg[i], self.seg[i-1])

    def update(self, k, value):

        X=2**self.K
        k += X-1
        self.seg[k] = value
        while k:
            k = (k-1)>>1
            self.seg[k] = self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2])

            

    def query(self, p, q):
        if q <= p:
            return self.basement
        num = 2**self.K
        p += num-1
        q += num-2
        res = self.basement
        while q-p > 1:
            if p & 1 == 0:
                res = self.func(res, self.seg[p])
            if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
            p = p>>1
            q = (q-1)>>1
        if p == q:
            res = self.func(res, self.seg[p])
        else:
            res = self.func(self.func(res, self.seg[p]), self.seg[q])
        return res

import sys
input=sys.stdin.readline

N=int(input())
S=list(input())
Q=int(input())
que=[tuple(input().split()) for i in range(Q)]
alpha="abcdefghijklmnopqrstuvwxyz"
Data={alpha[i]:[0]*N for i in range(26)}
for i in range(N):
    Data[S[i]][i]+=1
SEG={alpha[i]:SegTree(Data[alpha[i]],max,0) for i in range(26)}
for X,u,v in que:
    if X=="1":
        u=int(u)-1
        NOW=S[u]
        S[u]=v
        SEG[NOW].update(u,0)
        SEG[v].update(u,1)
    else:
        u,v=int(u)-1,int(v)-1
        res=0
        for j in range(26):
            res+=SEG[alpha[j]].query(u,v+1)
        print(res)
            
        
    
     class SegTree():
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.func = function
        self.basement = basement
        self.seg = [basement]*(2**(self.K+1))
        X=2**self.K
        for i,v in enumerate(lists):
            self.seg[i+X-1] = v

        for i in range(2*X-2, 0, -2):
            self.seg[(i-1)>>1] = self.func(self.seg[i], self.seg[i-1])

    def update(self, k, value):

        X=2**self.K
        k += X-1
        self.seg[k] = value
        while k:
            k = (k-1)>>1
            self.seg[k] = self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2])

            

    def query(self, p, q):
        if q <= p:
            return self.basement
        num = 2**self.K
        p += num-1
        q += num-2
        res = self.basement
        while q-p > 1:
            if p & 1 == 0:
                res = self.func(res, self.seg[p])
            if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
            p = p>>1
            q = (q-1)>>1
        if p == q:
            res = self.func(res, self.seg[p])
        else:
            res = self.func(self.func(res, self.seg[p]), self.seg[q])
        return res SegTree def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.func = function
        self.basement = basement
        self.seg = [basement]*(2**(self.K+1))
        X=2**self.K
        for i,v in enumerate(lists):
            self.seg[i+X-1] = v

        for i in range(2*X-2, 0, -2):
            self.seg[(i-1)>>1] = self.func(self.seg[i], self.seg[i-1])

     __init__ self.n = len(lists) self.n self n len(lists) len lists self.K = (self.n-1).bit_length() self.K self K (self.n-1).bit_length() self.n-1).bit_length self.n-1 self.n self n 1 bit_length self.func = function self.func self func function self.basement = basement self.basement self basement basement self.seg = [basement]*(2**(self.K+1)) self.seg self seg [basement]*(2**(self.K+1)) [basement] basement 2**(self.K+1) 2 self.K+1 self.K self K 1 X=2**self.K X 2**self.K 2 self.K self K for i,v in enumerate(lists):
            self.seg[i+X-1] = v

         i v enumerate(lists) enumerate lists self.seg[i+X-1] = v self.seg[i+X-1] self.seg self seg i+X-1 i+X i X 1 v for i in range(2*X-2, 0, -2):
            self.seg[(i-1)>>1] = self.func(self.seg[i], self.seg[i-1])

     i range(2*X-2, 0, -2) range 2*X-2 2*X 2 X 2 0 -2 self.seg[(i-1)>>1] = self.func(self.seg[i], self.seg[i-1]) self.seg[(i-1)>>1] self.seg self seg (i-1)>>1 i-1 i 1 1 self.func(self.seg[i], self.seg[i-1]) self.func self func self.seg[i] self.seg self seg i self.seg[i-1] self.seg self seg i-1 i 1 self self lists lists function function basement basement def update(self, k, value):

        X=2**self.K
        k += X-1
        self.seg[k] = value
        while k:
            k = (k-1)>>1
            self.seg[k] = self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2])

            

     update X=2**self.K X 2**self.K 2 self.K self K k += X-1 k X-1 X 1 self.seg[k] = value self.seg[k] self.seg self seg k value while k:
            k = (k-1)>>1
            self.seg[k] = self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2])

            

     k k = (k-1)>>1 k (k-1)>>1 k-1 k 1 1 self.seg[k] = self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2]) self.seg[k] self.seg self seg k self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2]) self.func self func self.seg[(k<<1)+1] self.seg self seg (k<<1)+1 k<<1 k 1 1 self.seg[(k<<1)+2] self.seg self seg (k<<1)+2 k<<1 k 1 2 self self k k value value def query(self, p, q):
        if q <= p:
            return self.basement
        num = 2**self.K
        p += num-1
        q += num-2
        res = self.basement
        while q-p > 1:
            if p & 1 == 0:
                res = self.func(res, self.seg[p])
            if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
            p = p>>1
            q = (q-1)>>1
        if p == q:
            res = self.func(res, self.seg[p])
        else:
            res = self.func(self.func(res, self.seg[p]), self.seg[q])
        return res query if q <= p:
            return self.basement
         q <= p q p return self.basement self.basement self basement num = 2**self.K num 2**self.K 2 self.K self K p += num-1 p num-1 num 1 q += num-2 q num-2 num 2 res = self.basement res self.basement self basement while q-p > 1:
            if p & 1 == 0:
                res = self.func(res, self.seg[p])
            if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
            p = p>>1
            q = (q-1)>>1
         q-p > 1 q-p q p 1 if p & 1 == 0:
                res = self.func(res, self.seg[p])
             p & 1 == 0 p & 1 p 1 0 res = self.func(res, self.seg[p]) res self.func(res, self.seg[p]) self.func self func res self.seg[p] self.seg self seg p if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
             q & 1 == 1 q & 1 q 1 1 res = self.func(res, self.seg[q]) res self.func(res, self.seg[q]) self.func self func res self.seg[q] self.seg self seg q q -= 1 q 1 p = p>>1 p p>>1 p 1 q = (q-1)>>1 q (q-1)>>1 q-1 q 1 1 if p == q:
            res = self.func(res, self.seg[p])
        else:
            res = self.func(self.func(res, self.seg[p]), self.seg[q])
         p == q p q res = self.func(res, self.seg[p]) res self.func(res, self.seg[p]) self.func self func res self.seg[p] self.seg self seg p res = self.func(self.func(res, self.seg[p]), self.seg[q]) res self.func(self.func(res, self.seg[p]), self.seg[q]) self.func self func self.func(res, self.seg[p]) self.func self func res self.seg[p] self.seg self seg p self.seg[q] self.seg self seg q return res res self self p p q q 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=list(input()) S list(input()) list input() input Q=int(input()) Q int(input()) int input() input tuple(input().split()) for i in range(Q) for i in range(Q) i range(Q) range Q for i in range(Q) tuple(input().split()) tuple input().split() ().split () input split que=[tuple(input().split()) for i in range(Q)] que [tuple(input().split()) for i in range(Q)] alpha="abcdefghijklmnopqrstuvwxyz" alpha "abcdefghijklmnopqrstuvwxyz" alpha[i]:[0]*N for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) alpha[i] alpha i [0]*N [0] 0 N Data={alpha[i]:[0]*N for i in range(26)} Data {alpha[i]:[0]*N for i in range(26)} for i in range(N):
    Data[S[i]][i]+=1 i range(N) range N Data[S[i]][i]+=1 Data[S[i]][i] [S[i]] Data S[i] S i i 1 alpha[i]:SegTree(Data[alpha[i]],max,0) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) alpha[i] alpha i SegTree(Data[alpha[i]],max,0) SegTree Data[alpha[i]] Data alpha[i] alpha i max 0 SEG={alpha[i]:SegTree(Data[alpha[i]],max,0) for i in range(26)} SEG {alpha[i]:SegTree(Data[alpha[i]],max,0) for i in range(26)} for X,u,v in que:
    if X=="1":
        u=int(u)-1
        NOW=S[u]
        S[u]=v
        SEG[NOW].update(u,0)
        SEG[v].update(u,1)
    else:
        u,v=int(u)-1,int(v)-1
        res=0
        for j in range(26):
            res+=SEG[alpha[j]].query(u,v+1)
        print(res)
            
        
    
     X u v que if X=="1":
        u=int(u)-1
        NOW=S[u]
        S[u]=v
        SEG[NOW].update(u,0)
        SEG[v].update(u,1)
    else:
        u,v=int(u)-1,int(v)-1
        res=0
        for j in range(26):
            res+=SEG[alpha[j]].query(u,v+1)
        print(res)
            
        
    
     X=="1" X "1" u=int(u)-1 u int(u)-1 int(u) int u 1 NOW=S[u] NOW S[u] S u S[u]=v S[u] S u v SEG[NOW].update(u,0) [NOW].update [NOW] SEG NOW update u 0 SEG[v].update(u,1) [v].update [v] SEG v update u 1 u,v=int(u)-1,int(v)-1 u int(u)-1 int(u) int u 1 v int(v)-1 int(v) int v 1 res=0 res 0 for j in range(26):
            res+=SEG[alpha[j]].query(u,v+1)
         j range(26) range 26 res+=SEG[alpha[j]].query(u,v+1) res SEG[alpha[j]].query(u,v+1) [alpha[j]].query [alpha[j]] SEG alpha[j] alpha j query u v+1 v 1 print(res) print res res+=SEG[alpha[j]].query(u,v+1) SEG[alpha[j]].query(u,v+1) res class SegTree():
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.func = function
        self.basement = basement
        self.seg = [basement]*(2**(self.K+1))
        X=2**self.K
        for i,v in enumerate(lists):
            self.seg[i+X-1] = v

        for i in range(2*X-2, 0, -2):
            self.seg[(i-1)>>1] = self.func(self.seg[i], self.seg[i-1])

    def update(self, k, value):

        X=2**self.K
        k += X-1
        self.seg[k] = value
        while k:
            k = (k-1)>>1
            self.seg[k] = self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2])

            

    def query(self, p, q):
        if q <= p:
            return self.basement
        num = 2**self.K
        p += num-1
        q += num-2
        res = self.basement
        while q-p > 1:
            if p & 1 == 0:
                res = self.func(res, self.seg[p])
            if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
            p = p>>1
            q = (q-1)>>1
        if p == q:
            res = self.func(res, self.seg[p])
        else:
            res = self.func(self.func(res, self.seg[p]), self.seg[q])
        return res class SegTree():
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.func = function
        self.basement = basement
        self.seg = [basement]*(2**(self.K+1))
        X=2**self.K
        for i,v in enumerate(lists):
            self.seg[i+X-1] = v

        for i in range(2*X-2, 0, -2):
            self.seg[(i-1)>>1] = self.func(self.seg[i], self.seg[i-1])

    def update(self, k, value):

        X=2**self.K
        k += X-1
        self.seg[k] = value
        while k:
            k = (k-1)>>1
            self.seg[k] = self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2])

            

    def query(self, p, q):
        if q <= p:
            return self.basement
        num = 2**self.K
        p += num-1
        q += num-2
        res = self.basement
        while q-p > 1:
            if p & 1 == 0:
                res = self.func(res, self.seg[p])
            if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
            p = p>>1
            q = (q-1)>>1
        if p == q:
            res = self.func(res, self.seg[p])
        else:
            res = self.func(self.func(res, self.seg[p]), self.seg[q])
        return res SegTree N=int(input()) int(input()) N v=int(u)-1,int(v)-1 int(v)-1 v u=int(u)-1 int(u)-1 u alpha="abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alpha u,v=int(u)-1,int(v)-1 int(u)-1 u res=0 0 res Q=int(input()) int(input()) Q SEG={alpha[i]:SegTree(Data[alpha[i]],max,0) for i in range(26)} {alpha[i]:SegTree(Data[alpha[i]],max,0) for i in range(26)} SEG input=sys.stdin.readline sys.stdin.readline input NOW=S[u] S[u] NOW S=list(input()) list(input()) S que=[tuple(input().split()) for i in range(Q)] [tuple(input().split()) for i in range(Q)] que Data={alpha[i]:[0]*N for i in range(26)} {alpha[i]:[0]*N for i in range(26)} Data
class SegTree():
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.func = function
        self.basement = basement
        self.seg = [basement]*(2**(self.K+1))
        X=2**self.K
        for i,v in enumerate(lists):
            self.seg[i+X-1] = v

        for i in range(2*X-2, 0, -2):
            self.seg[(i-1)>>1] = self.func(self.seg[i], self.seg[i-1])

    def update(self, k, value):

        X=2**self.K
        k += X-1
        self.seg[k] = value
        while k:
            k = (k-1)>>1
            self.seg[k] = self.func(self.seg[(k<<1)+1], self.seg[(k<<1)+2])

            

    def query(self, p, q):
        if q <= p:
            return self.basement
        num = 2**self.K
        p += num-1
        q += num-2
        res = self.basement
        while q-p > 1:
            if p & 1 == 0:
                res = self.func(res, self.seg[p])
            if q & 1 == 1:
                res = self.func(res, self.seg[q])
                q -= 1
            p = p>>1
            q = (q-1)>>1
        if p == q:
            res = self.func(res, self.seg[p])
        else:
            res = self.func(self.func(res, self.seg[p]), self.seg[q])
        return res

import sys
input=sys.stdin.readline

N=int(input())
S=list(input())
Q=int(input())
que=[tuple(input().split()) for i in range(Q)]
alpha="abcdefghijklmnopqrstuvwxyz"
Data={alpha[i]:[0]*N for i in range(26)}
for i in range(N):
    Data[S[i]][i]+=1
SEG={alpha[i]:SegTree(Data[alpha[i]],max,0) for i in range(26)}
for X,u,v in que:
    if X=="1":
        u=int(u)-1
        NOW=S[u]
        S[u]=v
        SEG[NOW].update(u,0)
        SEG[v].update(u,1)
    else:
        u,v=int(u)-1,int(v)-1
        res=0
        for j in range(26):
            res+=SEG[alpha[j]].query(u,v+1)
        print(res)
            
        
    
    
