class BinaryIndexedTree():
    def __init__(self, num):
        self.bit = [0]*(num+1) # 1-indexed
        self.num = num

    def sum(self, i):
        i += 1
        res = 0
        while (i > 0):
            res += self.bit[i]
            i -= i & -i
        return res
    
    def add(self, i, target):
        i += 1
        while i <= self.num:
            self.bit[i] += target
            i += i & -i
    
    # [l, r) 
    def query(self, l, r):
        return self.sum(r-1) - self.sum(l-1)

def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    anss = []
    bits = [BinaryIndexedTree(N) for i in range(26)]

    for index, c in enumerate(S):
        bits[ord(c) - ord('a')].add(index, 1)
    
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            index = int(query[1]) - 1
            target = query[2]
            if S[index] == target:
                continue
            else:
                bits[ord(S[index])-ord('a')].add(index, -1)
                S[index] = target
                bits[ord(target)-ord('a')].add(index, 1)
        else:
            l, r = map(int, query[1:])
            l-= 1; r-= 1
            ans = 0
            for i in range(26):
                if bits[i].query(l, r+1) > 0:
                    ans += 1
            anss.append(ans)
    print(*anss, sep="\n")

if __name__ == "__main__":
    main() class BinaryIndexedTree():
    def __init__(self, num):
        self.bit = [0]*(num+1) # 1-indexed
        self.num = num

    def sum(self, i):
        i += 1
        res = 0
        while (i > 0):
            res += self.bit[i]
            i -= i & -i
        return res
    
    def add(self, i, target):
        i += 1
        while i <= self.num:
            self.bit[i] += target
            i += i & -i
    
    # [l, r) 
    def query(self, l, r):
        return self.sum(r-1) - self.sum(l-1) BinaryIndexedTree def __init__(self, num):
        self.bit = [0]*(num+1) # 1-indexed
        self.num = num

     __init__ self.bit = [0]*(num+1) self.bit self bit [0]*(num+1) [0] 0 num+1 num 1 self.num = num self.num self num num self self num num def sum(self, i):
        i += 1
        res = 0
        while (i > 0):
            res += self.bit[i]
            i -= i & -i
        return res
    
     sum i += 1 i 1 res = 0 res 0 while (i > 0):
            res += self.bit[i]
            i -= i & -i
         i > 0 i 0 res += self.bit[i] res self.bit[i] self.bit self bit i i -= i & -i i i & -i i -i i return res res self self i i def add(self, i, target):
        i += 1
        while i <= self.num:
            self.bit[i] += target
            i += i & -i
    
    # [l, r) 
     add i += 1 i 1 while i <= self.num:
            self.bit[i] += target
            i += i & -i
    
    # [l, r) 
     i <= self.num i self.num self num self.bit[i] += target self.bit[i] self.bit self bit i target i += i & -i i i & -i i -i i self self i i target target def query(self, l, r):
        return self.sum(r-1) - self.sum(l-1) query return self.sum(r-1) - self.sum(l-1) self.sum(r-1) - self.sum(l-1) self.sum(r-1) self.sum self sum r-1 r 1 self.sum(l-1) self.sum self sum l-1 l 1 self self l l r r def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    anss = []
    bits = [BinaryIndexedTree(N) for i in range(26)]

    for index, c in enumerate(S):
        bits[ord(c) - ord('a')].add(index, 1)
    
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            index = int(query[1]) - 1
            target = query[2]
            if S[index] == target:
                continue
            else:
                bits[ord(S[index])-ord('a')].add(index, -1)
                S[index] = target
                bits[ord(target)-ord('a')].add(index, 1)
        else:
            l, r = map(int, query[1:])
            l-= 1; r-= 1
            ans = 0
            for i in range(26):
                if bits[i].query(l, r+1) > 0:
                    ans += 1
            anss.append(ans)
    print(*anss, sep="\n") main 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 anss = [] anss [] BinaryIndexedTree(N) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) BinaryIndexedTree(N) BinaryIndexedTree N bits = [BinaryIndexedTree(N) for i in range(26)] bits [BinaryIndexedTree(N) for i in range(26)] for index, c in enumerate(S):
        bits[ord(c) - ord('a')].add(index, 1)
    
     index c enumerate(S) enumerate S bits[ord(c) - ord('a')].add(index, 1) [ord(c) - ord('a')].add [ord(c) - ord('a')] bits ord(c) - ord('a') ord(c) ord c ord('a') ord 'a' add index 1 for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            index = int(query[1]) - 1
            target = query[2]
            if S[index] == target:
                continue
            else:
                bits[ord(S[index])-ord('a')].add(index, -1)
                S[index] = target
                bits[ord(target)-ord('a')].add(index, 1)
        else:
            l, r = map(int, query[1:])
            l-= 1; r-= 1
            ans = 0
            for i in range(26):
                if bits[i].query(l, r+1) > 0:
                    ans += 1
            anss.append(ans)
     _ range(Q) range Q query = input().split() query input().split() ().split () input split if query[0] == "1":
            index = int(query[1]) - 1
            target = query[2]
            if S[index] == target:
                continue
            else:
                bits[ord(S[index])-ord('a')].add(index, -1)
                S[index] = target
                bits[ord(target)-ord('a')].add(index, 1)
        else:
            l, r = map(int, query[1:])
            l-= 1; r-= 1
            ans = 0
            for i in range(26):
                if bits[i].query(l, r+1) > 0:
                    ans += 1
            anss.append(ans)
     query[0] == "1" query[0] query 0 "1" index = int(query[1]) - 1 index int(query[1]) - 1 int(query[1]) int query[1] query 1 1 target = query[2] target query[2] query 2 if S[index] == target:
                continue
            else:
                bits[ord(S[index])-ord('a')].add(index, -1)
                S[index] = target
                bits[ord(target)-ord('a')].add(index, 1)
         S[index] == target S[index] S index target continue bits[ord(S[index])-ord('a')].add(index, -1) [ord(S[index])-ord('a')].add [ord(S[index])-ord('a')] bits ord(S[index])-ord('a') ord(S[index]) ord S[index] S index ord('a') ord 'a' add index -1 S[index] = target S[index] S index target bits[ord(target)-ord('a')].add(index, 1) [ord(target)-ord('a')].add [ord(target)-ord('a')] bits ord(target)-ord('a') ord(target) ord target ord('a') ord 'a' add index 1 l, r = map(int, query[1:]) l map(int, query[1:]) map int query[1:] query 1: 1 r l-= 1 l 1 r-= 1 r 1 ans = 0 ans 0 for i in range(26):
                if bits[i].query(l, r+1) > 0:
                    ans += 1
             i range(26) range 26 if bits[i].query(l, r+1) > 0:
                    ans += 1
             bits[i].query(l, r+1) > 0 bits[i].query(l, r+1) [i].query [i] bits i query l r+1 r 1 0 ans += 1 ans 1 anss.append(ans) anss.append anss append ans print(*anss, sep="\n") print *anss anss sep="\n" sep "\n" if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    anss = []
    bits = [BinaryIndexedTree(N) for i in range(26)]

    for index, c in enumerate(S):
        bits[ord(c) - ord('a')].add(index, 1)
    
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            index = int(query[1]) - 1
            target = query[2]
            if S[index] == target:
                continue
            else:
                bits[ord(S[index])-ord('a')].add(index, -1)
                S[index] = target
                bits[ord(target)-ord('a')].add(index, 1)
        else:
            l, r = map(int, query[1:])
            l-= 1; r-= 1
            ans = 0
            for i in range(26):
                if bits[i].query(l, r+1) > 0:
                    ans += 1
            anss.append(ans)
    print(*anss, sep="\n") def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    anss = []
    bits = [BinaryIndexedTree(N) for i in range(26)]

    for index, c in enumerate(S):
        bits[ord(c) - ord('a')].add(index, 1)
    
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            index = int(query[1]) - 1
            target = query[2]
            if S[index] == target:
                continue
            else:
                bits[ord(S[index])-ord('a')].add(index, -1)
                S[index] = target
                bits[ord(target)-ord('a')].add(index, 1)
        else:
            l, r = map(int, query[1:])
            l-= 1; r-= 1
            ans = 0
            for i in range(26):
                if bits[i].query(l, r+1) > 0:
                    ans += 1
            anss.append(ans)
    print(*anss, sep="\n") main class BinaryIndexedTree():
    def __init__(self, num):
        self.bit = [0]*(num+1) # 1-indexed
        self.num = num

    def sum(self, i):
        i += 1
        res = 0
        while (i > 0):
            res += self.bit[i]
            i -= i & -i
        return res
    
    def add(self, i, target):
        i += 1
        while i <= self.num:
            self.bit[i] += target
            i += i & -i
    
    # [l, r) 
    def query(self, l, r):
        return self.sum(r-1) - self.sum(l-1) class BinaryIndexedTree():
    def __init__(self, num):
        self.bit = [0]*(num+1) # 1-indexed
        self.num = num

    def sum(self, i):
        i += 1
        res = 0
        while (i > 0):
            res += self.bit[i]
            i -= i & -i
        return res
    
    def add(self, i, target):
        i += 1
        while i <= self.num:
            self.bit[i] += target
            i += i & -i
    
    # [l, r) 
    def query(self, l, r):
        return self.sum(r-1) - self.sum(l-1) BinaryIndexedTree
class BinaryIndexedTree():
    def __init__(self, num):
        self.bit = [0]*(num+1) # 1-indexed
        self.num = num

    def sum(self, i):
        i += 1
        res = 0
        while (i > 0):
            res += self.bit[i]
            i -= i & -i
        return res
    
    def add(self, i, target):
        i += 1
        while i <= self.num:
            self.bit[i] += target
            i += i & -i
    
    # [l, r) 
    def query(self, l, r):
        return self.sum(r-1) - self.sum(l-1)

def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    anss = []
    bits = [BinaryIndexedTree(N) for i in range(26)]

    for index, c in enumerate(S):
        bits[ord(c) - ord('a')].add(index, 1)
    
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            index = int(query[1]) - 1
            target = query[2]
            if S[index] == target:
                continue
            else:
                bits[ord(S[index])-ord('a')].add(index, -1)
                S[index] = target
                bits[ord(target)-ord('a')].add(index, 1)
        else:
            l, r = map(int, query[1:])
            l-= 1; r-= 1
            ans = 0
            for i in range(26):
                if bits[i].query(l, r+1) > 0:
                    ans += 1
            anss.append(ans)
    print(*anss, sep="\n")

if __name__ == "__main__":
    main()
