class SegmentTree:
    def __init__(self, n, init_value, segfunc, ide_ele):
        self.N0 = 2 ** (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i in range(n):
            self.data[i + self.N0 - 1] = init_value[i]
        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, x):
        k = _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, _p, _q):
        p = _p
        q = _q
        if q <= p:
            return self.ide_ele
        
        p += self.N0 - 1
        q += self.N0 - 2
        res = self.ide_ele
        while 1 < q - p:
            if p & 1 == 0:
                res = self.segfunc(res, self.data[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.data[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.data[p])
        else:
            res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q])
        return res


def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


def solve():
    N = int(input())
    S = input()
    Q = int(input())
    
    init_val = [1 << ord(S[i]) - ord('a') for i in range(N)]
    
    def segfunc(a, b):
        return a | b
    
    seg_tree = SegmentTree(N, init_val, segfunc, 0)
    
    for _ in range(Q):
        cmd, *query = input().split()
        cmd = int(cmd)
        if cmd == 1:
            i = int(query[0]) - 1
            c = query[1]
            seg_tree.update(i, 1 << ord(c) - ord('a'))
        else:
            l = int(query[0]) - 1
            r = int(query[1])
            kind = seg_tree.query(l, r)
            print(popcount(kind))


if __name__ == '__main__':
    solve() class SegmentTree:
    def __init__(self, n, init_value, segfunc, ide_ele):
        self.N0 = 2 ** (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i in range(n):
            self.data[i + self.N0 - 1] = init_value[i]
        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, x):
        k = _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, _p, _q):
        p = _p
        q = _q
        if q <= p:
            return self.ide_ele
        
        p += self.N0 - 1
        q += self.N0 - 2
        res = self.ide_ele
        while 1 < q - p:
            if p & 1 == 0:
                res = self.segfunc(res, self.data[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.data[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.data[p])
        else:
            res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q])
        return res SegmentTree def __init__(self, n, init_value, segfunc, ide_ele):
        self.N0 = 2 ** (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i in range(n):
            self.data[i + self.N0 - 1] = init_value[i]
        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__ self.N0 = 2 ** (n - 1).bit_length() self.N0 self N0 2 ** (n - 1).bit_length() 2 (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 in range(n):
            self.data[i + self.N0 - 1] = init_value[i]
         i range(n) range n self.data[i + self.N0 - 1] = init_value[i] self.data[i + self.N0 - 1] self.data self data i + self.N0 - 1 i + self.N0 i self.N0 self N0 1 init_value[i] init_value i 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 n n init_value init_value segfunc segfunc ide_ele ide_ele def update(self, _k, x):
        k = _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 = _k + self.N0 - 1 k _k + self.N0 - 1 _k + self.N0 _k 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 _k x x def query(self, _p, _q):
        p = _p
        q = _q
        if q <= p:
            return self.ide_ele
        
        p += self.N0 - 1
        q += self.N0 - 2
        res = self.ide_ele
        while 1 < q - p:
            if p & 1 == 0:
                res = self.segfunc(res, self.data[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.data[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.data[p])
        else:
            res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q])
        return res query p = _p p _p q = _q q _q if q <= p:
            return self.ide_ele
        
         q <= p q p return self.ide_ele self.ide_ele self ide_ele p += self.N0 - 1 p self.N0 - 1 self.N0 self N0 1 q += self.N0 - 2 q self.N0 - 2 self.N0 self N0 2 res = self.ide_ele res self.ide_ele self ide_ele while 1 < q - p:
            if p & 1 == 0:
                res = self.segfunc(res, self.data[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.data[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
         1 < q - p 1 q - p q p if p & 1 == 0:
                res = self.segfunc(res, self.data[p])
             p & 1 == 0 p & 1 p 1 0 res = self.segfunc(res, self.data[p]) res self.segfunc(res, self.data[p]) self.segfunc self segfunc res self.data[p] self.data self data p if q & 1 == 1:
                res = self.segfunc(res, self.data[q])
                q -= 1
             q & 1 == 1 q & 1 q 1 1 res = self.segfunc(res, self.data[q]) res self.segfunc(res, self.data[q]) self.segfunc self segfunc res self.data[q] self.data self data q q -= 1 q 1 p = p // 2 p p // 2 p 2 q = (q - 1) // 2 q (q - 1) // 2 q - 1 q 1 2 if p == q:
            res = self.segfunc(res, self.data[p])
        else:
            res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q])
         p == q p q res = self.segfunc(res, self.data[p]) res self.segfunc(res, self.data[p]) self.segfunc self segfunc res self.data[p] self.data self data p res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q]) res self.segfunc(self.segfunc(res, self.data[p]), self.data[q]) self.segfunc self segfunc self.segfunc(res, self.data[p]) self.segfunc self segfunc res self.data[p] self.data self data p self.data[q] self.data self data q return res res self self _p _p _q _q def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f popcount x = x - ((x >> 1) & 0x5555555555555555) x x - ((x >> 1) & 0x5555555555555555) x (x >> 1) & 0x5555555555555555 x >> 1 x 1 0x5555555555555555 x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x & 0x3333333333333333 x 0x3333333333333333 (x >> 2) & 0x3333333333333333 x >> 2 x 2 0x3333333333333333 x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x + (x >> 4) x x >> 4 x 4 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x x + (x >> 8) x x >> 8 x 8 x = x + (x >> 16) x x + (x >> 16) x x >> 16 x 16 x = x + (x >> 32) x x + (x >> 32) x x >> 32 x 32 return x & 0x0000007f x & 0x0000007f x 0x0000007f x x def solve():
    N = int(input())
    S = input()
    Q = int(input())
    
    init_val = [1 << ord(S[i]) - ord('a') for i in range(N)]
    
    def segfunc(a, b):
        return a | b
    
    seg_tree = SegmentTree(N, init_val, segfunc, 0)
    
    for _ in range(Q):
        cmd, *query = input().split()
        cmd = int(cmd)
        if cmd == 1:
            i = int(query[0]) - 1
            c = query[1]
            seg_tree.update(i, 1 << ord(c) - ord('a'))
        else:
            l = int(query[0]) - 1
            r = int(query[1])
            kind = seg_tree.query(l, r)
            print(popcount(kind)) solve N = int(input()) N int(input()) int input() input S = input() S input() input Q = int(input()) Q int(input()) int input() input 1 << ord(S[i]) - ord('a') for i in range(N) for i in range(N) i range(N) range N for i in range(N) 1 << ord(S[i]) - ord('a') 1 ord(S[i]) - ord('a') ord(S[i]) ord S[i] S i ord('a') ord 'a' init_val = [1 << ord(S[i]) - ord('a') for i in range(N)] init_val [1 << ord(S[i]) - ord('a') for i in range(N)] def segfunc(a, b):
        return a | b
    
     segfunc return a | b a | b a b a a b b seg_tree = SegmentTree(N, init_val, segfunc, 0) seg_tree SegmentTree(N, init_val, segfunc, 0) SegmentTree N init_val segfunc 0 for _ in range(Q):
        cmd, *query = input().split()
        cmd = int(cmd)
        if cmd == 1:
            i = int(query[0]) - 1
            c = query[1]
            seg_tree.update(i, 1 << ord(c) - ord('a'))
        else:
            l = int(query[0]) - 1
            r = int(query[1])
            kind = seg_tree.query(l, r)
            print(popcount(kind)) _ range(Q) range Q cmd, *query = input().split() cmd input().split() ().split () input split *query query cmd = int(cmd) cmd int(cmd) int cmd if cmd == 1:
            i = int(query[0]) - 1
            c = query[1]
            seg_tree.update(i, 1 << ord(c) - ord('a'))
        else:
            l = int(query[0]) - 1
            r = int(query[1])
            kind = seg_tree.query(l, r)
            print(popcount(kind)) cmd == 1 cmd 1 i = int(query[0]) - 1 i int(query[0]) - 1 int(query[0]) int query[0] query 0 1 c = query[1] c query[1] query 1 seg_tree.update(i, 1 << ord(c) - ord('a')) seg_tree.update seg_tree update i 1 << ord(c) - ord('a') 1 ord(c) - ord('a') ord(c) ord c ord('a') ord 'a' l = int(query[0]) - 1 l int(query[0]) - 1 int(query[0]) int query[0] query 0 1 r = int(query[1]) r int(query[1]) int query[1] query 1 kind = seg_tree.query(l, r) kind seg_tree.query(l, r) seg_tree.query seg_tree query l r print(popcount(kind)) print popcount(kind) popcount kind if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f popcount def solve():
    N = int(input())
    S = input()
    Q = int(input())
    
    init_val = [1 << ord(S[i]) - ord('a') for i in range(N)]
    
    def segfunc(a, b):
        return a | b
    
    seg_tree = SegmentTree(N, init_val, segfunc, 0)
    
    for _ in range(Q):
        cmd, *query = input().split()
        cmd = int(cmd)
        if cmd == 1:
            i = int(query[0]) - 1
            c = query[1]
            seg_tree.update(i, 1 << ord(c) - ord('a'))
        else:
            l = int(query[0]) - 1
            r = int(query[1])
            kind = seg_tree.query(l, r)
            print(popcount(kind)) def solve():
    N = int(input())
    S = input()
    Q = int(input())
    
    init_val = [1 << ord(S[i]) - ord('a') for i in range(N)]
    
    def segfunc(a, b):
        return a | b
    
    seg_tree = SegmentTree(N, init_val, segfunc, 0)
    
    for _ in range(Q):
        cmd, *query = input().split()
        cmd = int(cmd)
        if cmd == 1:
            i = int(query[0]) - 1
            c = query[1]
            seg_tree.update(i, 1 << ord(c) - ord('a'))
        else:
            l = int(query[0]) - 1
            r = int(query[1])
            kind = seg_tree.query(l, r)
            print(popcount(kind)) solve class SegmentTree:
    def __init__(self, n, init_value, segfunc, ide_ele):
        self.N0 = 2 ** (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i in range(n):
            self.data[i + self.N0 - 1] = init_value[i]
        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, x):
        k = _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, _p, _q):
        p = _p
        q = _q
        if q <= p:
            return self.ide_ele
        
        p += self.N0 - 1
        q += self.N0 - 2
        res = self.ide_ele
        while 1 < q - p:
            if p & 1 == 0:
                res = self.segfunc(res, self.data[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.data[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.data[p])
        else:
            res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q])
        return res class SegmentTree:
    def __init__(self, n, init_value, segfunc, ide_ele):
        self.N0 = 2 ** (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i in range(n):
            self.data[i + self.N0 - 1] = init_value[i]
        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, x):
        k = _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, _p, _q):
        p = _p
        q = _q
        if q <= p:
            return self.ide_ele
        
        p += self.N0 - 1
        q += self.N0 - 2
        res = self.ide_ele
        while 1 < q - p:
            if p & 1 == 0:
                res = self.segfunc(res, self.data[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.data[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.data[p])
        else:
            res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q])
        return res SegmentTree
class SegmentTree:
    def __init__(self, n, init_value, segfunc, ide_ele):
        self.N0 = 2 ** (n - 1).bit_length()
        self.ide_ele = ide_ele
        self.data = [ide_ele] * (2 * self.N0)
        self.segfunc = segfunc
        
        for i in range(n):
            self.data[i + self.N0 - 1] = init_value[i]
        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, x):
        k = _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, _p, _q):
        p = _p
        q = _q
        if q <= p:
            return self.ide_ele
        
        p += self.N0 - 1
        q += self.N0 - 2
        res = self.ide_ele
        while 1 < q - p:
            if p & 1 == 0:
                res = self.segfunc(res, self.data[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.data[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.data[p])
        else:
            res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q])
        return res


def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


def solve():
    N = int(input())
    S = input()
    Q = int(input())
    
    init_val = [1 << ord(S[i]) - ord('a') for i in range(N)]
    
    def segfunc(a, b):
        return a | b
    
    seg_tree = SegmentTree(N, init_val, segfunc, 0)
    
    for _ in range(Q):
        cmd, *query = input().split()
        cmd = int(cmd)
        if cmd == 1:
            i = int(query[0]) - 1
            c = query[1]
            seg_tree.update(i, 1 << ord(c) - ord('a'))
        else:
            l = int(query[0]) - 1
            r = int(query[1])
            kind = seg_tree.query(l, r)
            print(popcount(kind))


if __name__ == '__main__':
    solve()
