class SegTree():
    def segFunc(self, x, y):
        return x+y
    def searchIndexFunc(self, val):
        return True
    def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2])
    def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def addition(self, idx, val):
        idx += self.num-1
        self.seg[idx] += val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def multiplication(self, idx, val):
        idx += self.num-1
        self.seg[idx] *= val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segFunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segFunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segFunc(res, self.seg[begin])
        else:
            res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end])
        return res
    def getLargestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R)//2
            if self.searchIndexFunc(self.query(P, R)):
                L = P
            else:
                R = P
        return L
    def getSmallestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R+1)//2
            if self.searchIndexFunc(self.query(L, P)):
                R = P
            else:
                L = P
        return L

def main():
    n = int(input())
    s = input()
    alp = [[0]*n for _ in range(26)]
    for i, c in enumerate(s):
        alp[ord(c) - ord("a")][i] = 1
    seg = [SegTree(0, alp[i]) for i in range(26)]
    q = int(input())
    ans = []
    for _ in range(q):
        a, b, c = map(str, input().split())
        if a == "1":
            b = int(b) - 1
            for i in range(26):
                if alp[i][b] == 1:
                    alp[i][b] = 0
                    seg[i].update(b, 0)
            alp[ord(c) - ord("a")][b] = 1
            seg[ord(c) - ord("a")].update(b, 1)
        else:
            b, c = int(b)-1, int(c)
            cnt = 0
            for i in range(26):
                if seg[i].query(b, c) > 0:
                    cnt += 1
            ans.append(cnt)
    for v in ans:
        print(v)

if __name__ == "__main__":
    main() class SegTree():
    def segFunc(self, x, y):
        return x+y
    def searchIndexFunc(self, val):
        return True
    def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2])
    def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def addition(self, idx, val):
        idx += self.num-1
        self.seg[idx] += val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def multiplication(self, idx, val):
        idx += self.num-1
        self.seg[idx] *= val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segFunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segFunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segFunc(res, self.seg[begin])
        else:
            res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end])
        return res
    def getLargestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R)//2
            if self.searchIndexFunc(self.query(P, R)):
                L = P
            else:
                R = P
        return L
    def getSmallestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R+1)//2
            if self.searchIndexFunc(self.query(L, P)):
                R = P
            else:
                L = P
        return L SegTree def segFunc(self, x, y):
        return x+y
     segFunc return x+y x+y x y self self x x y y def searchIndexFunc(self, val):
        return True
     searchIndexFunc return True True self self val val def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2])
     __init__ n = len(init_val) n len(init_val) len init_val self.ide_ele = ide self.ide_ele self ide_ele ide self.num = 2**(n-1).bit_length() self.num self num 2**(n-1).bit_length() 2 (n-1).bit_length() n-1).bit_length n-1 n 1 bit_length self.seg = [self.ide_ele] * 2 * self.num self.seg self seg [self.ide_ele] * 2 * self.num [self.ide_ele] * 2 [self.ide_ele] self.ide_ele self ide_ele 2 self.num self num for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
         i range(n) range n self.seg[i+self.num-1] = init_val[i] self.seg[i+self.num-1] self.seg self seg i+self.num-1 i+self.num i self.num self num 1 init_val[i] init_val i for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2])
     i range(self.num-2,-1,-1) range self.num-2 self.num self num 2 -1 -1 self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2]) self.seg[i] self.seg self seg i self.segFunc(self.seg[2*i+1],self.seg[2*i+2]) self.segFunc self segFunc self.seg[2*i+1] self.seg self seg 2*i+1 2*i 2 i 1 self.seg[2*i+2] self.seg self seg 2*i+2 2*i 2 i 2 self self ide ide init_val init_val def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
     update idx += self.num-1 idx self.num-1 self.num self num 1 self.seg[idx] = val self.seg[idx] self.seg self seg idx val while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
     idx idx = (idx-1)//2 idx (idx-1)//2 idx-1 idx 1 2 self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2]) self.seg[idx] self.seg self seg idx self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2]) self.segFunc self segFunc self.seg[idx*2+1] self.seg self seg idx*2+1 idx*2 idx 2 1 self.seg[idx*2+2] self.seg self seg idx*2+2 idx*2 idx 2 2 self self idx idx val val def addition(self, idx, val):
        idx += self.num-1
        self.seg[idx] += val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
     addition idx += self.num-1 idx self.num-1 self.num self num 1 self.seg[idx] += val self.seg[idx] self.seg self seg idx val while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
     idx idx = (idx-1)//2 idx (idx-1)//2 idx-1 idx 1 2 self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2]) self.seg[idx] self.seg self seg idx self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2]) self.segFunc self segFunc self.seg[idx*2+1] self.seg self seg idx*2+1 idx*2 idx 2 1 self.seg[idx*2+2] self.seg self seg idx*2+2 idx*2 idx 2 2 self self idx idx val val def multiplication(self, idx, val):
        idx += self.num-1
        self.seg[idx] *= val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
     multiplication idx += self.num-1 idx self.num-1 self.num self num 1 self.seg[idx] *= val self.seg[idx] self.seg self seg idx val while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
     idx idx = (idx-1)//2 idx (idx-1)//2 idx-1 idx 1 2 self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2]) self.seg[idx] self.seg self seg idx self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2]) self.segFunc self segFunc self.seg[idx*2+1] self.seg self seg idx*2+1 idx*2 idx 2 1 self.seg[idx*2+2] self.seg self seg idx*2+2 idx*2 idx 2 2 self self idx idx val val def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segFunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segFunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segFunc(res, self.seg[begin])
        else:
            res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end])
        return res
     query if end <= begin:
            return self.ide_ele
         end <= begin end begin return self.ide_ele self.ide_ele self ide_ele begin += self.num-1 begin self.num-1 self.num self num 1 end += self.num-2 end self.num-2 self.num self num 2 res = self.ide_ele res self.ide_ele self ide_ele while begin + 1 < end:
            if begin&1 == 0:
                res = self.segFunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segFunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
         begin + 1 < end begin + 1 begin 1 end if begin&1 == 0:
                res = self.segFunc(res, self.seg[begin])
             begin&1 == 0 begin&1 begin 1 0 res = self.segFunc(res, self.seg[begin]) res self.segFunc(res, self.seg[begin]) self.segFunc self segFunc res self.seg[begin] self.seg self seg begin if end&1 == 1:
                res = self.segFunc(res, self.seg[end])
                end -= 1
             end&1 == 1 end&1 end 1 1 res = self.segFunc(res, self.seg[end]) res self.segFunc(res, self.seg[end]) self.segFunc self segFunc res self.seg[end] self.seg self seg end end -= 1 end 1 begin = begin//2 begin begin//2 begin 2 end = (end-1)//2 end (end-1)//2 end-1 end 1 2 if begin == end:
            res = self.segFunc(res, self.seg[begin])
        else:
            res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end])
         begin == end begin end res = self.segFunc(res, self.seg[begin]) res self.segFunc(res, self.seg[begin]) self.segFunc self segFunc res self.seg[begin] self.seg self seg begin res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end]) res self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end]) self.segFunc self segFunc self.segFunc(res, self.seg[begin]) self.segFunc self segFunc res self.seg[begin] self.seg self seg begin self.seg[end] self.seg self seg end return res res self self begin begin end end def getLargestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R)//2
            if self.searchIndexFunc(self.query(P, R)):
                L = P
            else:
                R = P
        return L
     getLargestIndex L, R = begin, end L begin R end if not self.searchIndexFunc(self.query(begin, end)):
            return None
         not self.searchIndexFunc(self.query(begin, end)) self.searchIndexFunc(self.query(begin, end)) self.searchIndexFunc self searchIndexFunc self.query(begin, end) self.query self query begin end return None None while L+1 < R:
            P = (L+R)//2
            if self.searchIndexFunc(self.query(P, R)):
                L = P
            else:
                R = P
         L+1 < R L+1 L 1 R P = (L+R)//2 P (L+R)//2 L+R L R 2 if self.searchIndexFunc(self.query(P, R)):
                L = P
            else:
                R = P
         self.searchIndexFunc(self.query(P, R)) self.searchIndexFunc self searchIndexFunc self.query(P, R) self.query self query P R L = P L P R = P R P return L L self self begin begin end end def getSmallestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R+1)//2
            if self.searchIndexFunc(self.query(L, P)):
                R = P
            else:
                L = P
        return L getSmallestIndex L, R = begin, end L begin R end if not self.searchIndexFunc(self.query(begin, end)):
            return None
         not self.searchIndexFunc(self.query(begin, end)) self.searchIndexFunc(self.query(begin, end)) self.searchIndexFunc self searchIndexFunc self.query(begin, end) self.query self query begin end return None None while L+1 < R:
            P = (L+R+1)//2
            if self.searchIndexFunc(self.query(L, P)):
                R = P
            else:
                L = P
         L+1 < R L+1 L 1 R P = (L+R+1)//2 P (L+R+1)//2 L+R+1 L+R L R 1 2 if self.searchIndexFunc(self.query(L, P)):
                R = P
            else:
                L = P
         self.searchIndexFunc(self.query(L, P)) self.searchIndexFunc self searchIndexFunc self.query(L, P) self.query self query L P R = P R P L = P L P return L L self self begin begin end end def main():
    n = int(input())
    s = input()
    alp = [[0]*n for _ in range(26)]
    for i, c in enumerate(s):
        alp[ord(c) - ord("a")][i] = 1
    seg = [SegTree(0, alp[i]) for i in range(26)]
    q = int(input())
    ans = []
    for _ in range(q):
        a, b, c = map(str, input().split())
        if a == "1":
            b = int(b) - 1
            for i in range(26):
                if alp[i][b] == 1:
                    alp[i][b] = 0
                    seg[i].update(b, 0)
            alp[ord(c) - ord("a")][b] = 1
            seg[ord(c) - ord("a")].update(b, 1)
        else:
            b, c = int(b)-1, int(c)
            cnt = 0
            for i in range(26):
                if seg[i].query(b, c) > 0:
                    cnt += 1
            ans.append(cnt)
    for v in ans:
        print(v) main n = int(input()) n int(input()) int input() input s = input() s input() input [0]*n for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0]*n [0] 0 n alp = [[0]*n for _ in range(26)] alp [[0]*n for _ in range(26)] for i, c in enumerate(s):
        alp[ord(c) - ord("a")][i] = 1
     i c enumerate(s) enumerate s alp[ord(c) - ord("a")][i] = 1 alp[ord(c) - ord("a")][i] [ord(c) - ord("a")] alp ord(c) - ord("a") ord(c) ord c ord("a") ord "a" i 1 SegTree(0, alp[i]) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) SegTree(0, alp[i]) SegTree 0 alp[i] alp i seg = [SegTree(0, alp[i]) for i in range(26)] seg [SegTree(0, alp[i]) for i in range(26)] q = int(input()) q int(input()) int input() input ans = [] ans [] for _ in range(q):
        a, b, c = map(str, input().split())
        if a == "1":
            b = int(b) - 1
            for i in range(26):
                if alp[i][b] == 1:
                    alp[i][b] = 0
                    seg[i].update(b, 0)
            alp[ord(c) - ord("a")][b] = 1
            seg[ord(c) - ord("a")].update(b, 1)
        else:
            b, c = int(b)-1, int(c)
            cnt = 0
            for i in range(26):
                if seg[i].query(b, c) > 0:
                    cnt += 1
            ans.append(cnt)
     _ range(q) range q a, b, c = map(str, input().split()) a map(str, input().split()) map str input().split() ().split () input split b c if a == "1":
            b = int(b) - 1
            for i in range(26):
                if alp[i][b] == 1:
                    alp[i][b] = 0
                    seg[i].update(b, 0)
            alp[ord(c) - ord("a")][b] = 1
            seg[ord(c) - ord("a")].update(b, 1)
        else:
            b, c = int(b)-1, int(c)
            cnt = 0
            for i in range(26):
                if seg[i].query(b, c) > 0:
                    cnt += 1
            ans.append(cnt)
     a == "1" a "1" b = int(b) - 1 b int(b) - 1 int(b) int b 1 for i in range(26):
                if alp[i][b] == 1:
                    alp[i][b] = 0
                    seg[i].update(b, 0)
             i range(26) range 26 if alp[i][b] == 1:
                    alp[i][b] = 0
                    seg[i].update(b, 0)
             alp[i][b] == 1 alp[i][b] [i] alp i b 1 alp[i][b] = 0 alp[i][b] [i] alp i b 0 seg[i].update(b, 0) [i].update [i] seg i update b 0 alp[ord(c) - ord("a")][b] = 1 alp[ord(c) - ord("a")][b] [ord(c) - ord("a")] alp ord(c) - ord("a") ord(c) ord c ord("a") ord "a" b 1 seg[ord(c) - ord("a")].update(b, 1) [ord(c) - ord("a")].update [ord(c) - ord("a")] seg ord(c) - ord("a") ord(c) ord c ord("a") ord "a" update b 1 b, c = int(b)-1, int(c) b int(b)-1 int(b) int b 1 c int(c) int c cnt = 0 cnt 0 for i in range(26):
                if seg[i].query(b, c) > 0:
                    cnt += 1
             i range(26) range 26 if seg[i].query(b, c) > 0:
                    cnt += 1
             seg[i].query(b, c) > 0 seg[i].query(b, c) [i].query [i] seg i query b c 0 cnt += 1 cnt 1 ans.append(cnt) ans.append ans append cnt for v in ans:
        print(v) v ans print(v) print v if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main class SegTree():
    def segFunc(self, x, y):
        return x+y
    def searchIndexFunc(self, val):
        return True
    def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2])
    def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def addition(self, idx, val):
        idx += self.num-1
        self.seg[idx] += val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def multiplication(self, idx, val):
        idx += self.num-1
        self.seg[idx] *= val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segFunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segFunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segFunc(res, self.seg[begin])
        else:
            res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end])
        return res
    def getLargestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R)//2
            if self.searchIndexFunc(self.query(P, R)):
                L = P
            else:
                R = P
        return L
    def getSmallestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R+1)//2
            if self.searchIndexFunc(self.query(L, P)):
                R = P
            else:
                L = P
        return L class SegTree():
    def segFunc(self, x, y):
        return x+y
    def searchIndexFunc(self, val):
        return True
    def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2])
    def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def addition(self, idx, val):
        idx += self.num-1
        self.seg[idx] += val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def multiplication(self, idx, val):
        idx += self.num-1
        self.seg[idx] *= val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segFunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segFunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segFunc(res, self.seg[begin])
        else:
            res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end])
        return res
    def getLargestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R)//2
            if self.searchIndexFunc(self.query(P, R)):
                L = P
            else:
                R = P
        return L
    def getSmallestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R+1)//2
            if self.searchIndexFunc(self.query(L, P)):
                R = P
            else:
                L = P
        return L SegTree def main():
    n = int(input())
    s = input()
    alp = [[0]*n for _ in range(26)]
    for i, c in enumerate(s):
        alp[ord(c) - ord("a")][i] = 1
    seg = [SegTree(0, alp[i]) for i in range(26)]
    q = int(input())
    ans = []
    for _ in range(q):
        a, b, c = map(str, input().split())
        if a == "1":
            b = int(b) - 1
            for i in range(26):
                if alp[i][b] == 1:
                    alp[i][b] = 0
                    seg[i].update(b, 0)
            alp[ord(c) - ord("a")][b] = 1
            seg[ord(c) - ord("a")].update(b, 1)
        else:
            b, c = int(b)-1, int(c)
            cnt = 0
            for i in range(26):
                if seg[i].query(b, c) > 0:
                    cnt += 1
            ans.append(cnt)
    for v in ans:
        print(v) def main():
    n = int(input())
    s = input()
    alp = [[0]*n for _ in range(26)]
    for i, c in enumerate(s):
        alp[ord(c) - ord("a")][i] = 1
    seg = [SegTree(0, alp[i]) for i in range(26)]
    q = int(input())
    ans = []
    for _ in range(q):
        a, b, c = map(str, input().split())
        if a == "1":
            b = int(b) - 1
            for i in range(26):
                if alp[i][b] == 1:
                    alp[i][b] = 0
                    seg[i].update(b, 0)
            alp[ord(c) - ord("a")][b] = 1
            seg[ord(c) - ord("a")].update(b, 1)
        else:
            b, c = int(b)-1, int(c)
            cnt = 0
            for i in range(26):
                if seg[i].query(b, c) > 0:
                    cnt += 1
            ans.append(cnt)
    for v in ans:
        print(v) main
class SegTree():
    def segFunc(self, x, y):
        return x+y
    def searchIndexFunc(self, val):
        return True
    def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segFunc(self.seg[2*i+1],self.seg[2*i+2])
    def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def addition(self, idx, val):
        idx += self.num-1
        self.seg[idx] += val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def multiplication(self, idx, val):
        idx += self.num-1
        self.seg[idx] *= val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segFunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segFunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segFunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segFunc(res, self.seg[begin])
        else:
            res = self.segFunc(self.segFunc(res, self.seg[begin]), self.seg[end])
        return res
    def getLargestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R)//2
            if self.searchIndexFunc(self.query(P, R)):
                L = P
            else:
                R = P
        return L
    def getSmallestIndex(self, begin, end):
        L, R = begin, end
        if not self.searchIndexFunc(self.query(begin, end)):
            return None
        while L+1 < R:
            P = (L+R+1)//2
            if self.searchIndexFunc(self.query(L, P)):
                R = P
            else:
                L = P
        return L

def main():
    n = int(input())
    s = input()
    alp = [[0]*n for _ in range(26)]
    for i, c in enumerate(s):
        alp[ord(c) - ord("a")][i] = 1
    seg = [SegTree(0, alp[i]) for i in range(26)]
    q = int(input())
    ans = []
    for _ in range(q):
        a, b, c = map(str, input().split())
        if a == "1":
            b = int(b) - 1
            for i in range(26):
                if alp[i][b] == 1:
                    alp[i][b] = 0
                    seg[i].update(b, 0)
            alp[ord(c) - ord("a")][b] = 1
            seg[ord(c) - ord("a")].update(b, 1)
        else:
            b, c = int(b)-1, int(c)
            cnt = 0
            for i in range(26):
                if seg[i].query(b, c) > 0:
                    cnt += 1
            ans.append(cnt)
    for v in ans:
        print(v)

if __name__ == "__main__":
    main()