import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():

    class BinaryIndexedTree():
        def __init__(self, n):
            self.n = n
            self.bit = [0]*(n+1)

        def add(self, item, pos):
            index = pos
            while index < self.n+1:
                self.bit[index] += item
                index += index & (-index)

        def sum(self, pos):
            ret = 0
            index = pos
            while index > 0:
                ret += self.bit[index]
                index -= index & -index
            return ret

    N = int(input())
    S = list(input())
    Q = int(input())
    Query = [input().split() for _ in range(Q)] 

    pos_bit_list = [BinaryIndexedTree(len(S)) for _ in range(26)]

    for i, c in enumerate(S):
        pos_bit_list[ord(c)-ord('a')].add(1, i+1)

    for q in Query:
        if q[0] == '1':
            pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1]))
            pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1]))
            S[int(q[1])-1] = q[2]
        else:
            print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0]))

if __name__ == '__main__':
    resolve() import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def resolve():

    class BinaryIndexedTree():
        def __init__(self, n):
            self.n = n
            self.bit = [0]*(n+1)

        def add(self, item, pos):
            index = pos
            while index < self.n+1:
                self.bit[index] += item
                index += index & (-index)

        def sum(self, pos):
            ret = 0
            index = pos
            while index > 0:
                ret += self.bit[index]
                index -= index & -index
            return ret

    N = int(input())
    S = list(input())
    Q = int(input())
    Query = [input().split() for _ in range(Q)] 

    pos_bit_list = [BinaryIndexedTree(len(S)) for _ in range(26)]

    for i, c in enumerate(S):
        pos_bit_list[ord(c)-ord('a')].add(1, i+1)

    for q in Query:
        if q[0] == '1':
            pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1]))
            pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1]))
            S[int(q[1])-1] = q[2]
        else:
            print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0])) resolve class BinaryIndexedTree():
        def __init__(self, n):
            self.n = n
            self.bit = [0]*(n+1)

        def add(self, item, pos):
            index = pos
            while index < self.n+1:
                self.bit[index] += item
                index += index & (-index)

        def sum(self, pos):
            ret = 0
            index = pos
            while index > 0:
                ret += self.bit[index]
                index -= index & -index
            return ret

     BinaryIndexedTree def __init__(self, n):
            self.n = n
            self.bit = [0]*(n+1)

         __init__ self.n = n self.n self n n self.bit = [0]*(n+1) self.bit self bit [0]*(n+1) [0] 0 n+1 n 1 self self n n def add(self, item, pos):
            index = pos
            while index < self.n+1:
                self.bit[index] += item
                index += index & (-index)

         add index = pos index pos while index < self.n+1:
                self.bit[index] += item
                index += index & (-index)

         index < self.n+1 index self.n+1 self.n self n 1 self.bit[index] += item self.bit[index] self.bit self bit index item index += index & (-index) index index & (-index) index -index index self self item item pos pos def sum(self, pos):
            ret = 0
            index = pos
            while index > 0:
                ret += self.bit[index]
                index -= index & -index
            return ret

     sum ret = 0 ret 0 index = pos index pos while index > 0:
                ret += self.bit[index]
                index -= index & -index
             index > 0 index 0 ret += self.bit[index] ret self.bit[index] self.bit self bit index index -= index & -index index index & -index index -index index return ret ret self self pos pos 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 input().split() for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) input().split() ().split () input split Query = [input().split() for _ in range(Q)] Query [input().split() for _ in range(Q)] BinaryIndexedTree(len(S)) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BinaryIndexedTree(len(S)) BinaryIndexedTree len(S) len S pos_bit_list = [BinaryIndexedTree(len(S)) for _ in range(26)] pos_bit_list [BinaryIndexedTree(len(S)) for _ in range(26)] for i, c in enumerate(S):
        pos_bit_list[ord(c)-ord('a')].add(1, i+1)

     i c enumerate(S) enumerate S pos_bit_list[ord(c)-ord('a')].add(1, i+1) [ord(c)-ord('a')].add [ord(c)-ord('a')] pos_bit_list ord(c)-ord('a') ord(c) ord c ord('a') ord 'a' add 1 i+1 i 1 for q in Query:
        if q[0] == '1':
            pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1]))
            pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1]))
            S[int(q[1])-1] = q[2]
        else:
            print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0])) q Query if q[0] == '1':
            pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1]))
            pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1]))
            S[int(q[1])-1] = q[2]
        else:
            print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0])) q[0] == '1' q[0] q 0 '1' pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1])) [ord(S[int(q[1])-1])-ord('a')].add [ord(S[int(q[1])-1])-ord('a')] pos_bit_list ord(S[int(q[1])-1])-ord('a') ord(S[int(q[1])-1]) ord S[int(q[1])-1] S int(q[1])-1 int(q[1]) int q[1] q 1 1 ord('a') ord 'a' add -1 int(q[1]) int q[1] q 1 pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1])) [ord(q[2])-ord('a')].add [ord(q[2])-ord('a')] pos_bit_list ord(q[2])-ord('a') ord(q[2]) ord q[2] q 2 ord('a') ord 'a' add 1 int(q[1]) int q[1] q 1 S[int(q[1])-1] = q[2] S[int(q[1])-1] S int(q[1])-1 int(q[1]) int q[1] q 1 1 q[2] q 2 p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0 for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0 p pos_bit_list p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0 p.sum(int(q[2])) - p.sum(int(q[1])-1) p.sum(int(q[2])) p.sum p sum int(q[2]) int q[2] q 2 p.sum(int(q[1])-1) p.sum p sum int(q[1])-1 int(q[1]) int q[1] q 1 1 0 if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0 p print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0])) print len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0]) len [p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0] if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve def resolve():

    class BinaryIndexedTree():
        def __init__(self, n):
            self.n = n
            self.bit = [0]*(n+1)

        def add(self, item, pos):
            index = pos
            while index < self.n+1:
                self.bit[index] += item
                index += index & (-index)

        def sum(self, pos):
            ret = 0
            index = pos
            while index > 0:
                ret += self.bit[index]
                index -= index & -index
            return ret

    N = int(input())
    S = list(input())
    Q = int(input())
    Query = [input().split() for _ in range(Q)] 

    pos_bit_list = [BinaryIndexedTree(len(S)) for _ in range(26)]

    for i, c in enumerate(S):
        pos_bit_list[ord(c)-ord('a')].add(1, i+1)

    for q in Query:
        if q[0] == '1':
            pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1]))
            pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1]))
            S[int(q[1])-1] = q[2]
        else:
            print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0])) def resolve():

    class BinaryIndexedTree():
        def __init__(self, n):
            self.n = n
            self.bit = [0]*(n+1)

        def add(self, item, pos):
            index = pos
            while index < self.n+1:
                self.bit[index] += item
                index += index & (-index)

        def sum(self, pos):
            ret = 0
            index = pos
            while index > 0:
                ret += self.bit[index]
                index -= index & -index
            return ret

    N = int(input())
    S = list(input())
    Q = int(input())
    Query = [input().split() for _ in range(Q)] 

    pos_bit_list = [BinaryIndexedTree(len(S)) for _ in range(26)]

    for i, c in enumerate(S):
        pos_bit_list[ord(c)-ord('a')].add(1, i+1)

    for q in Query:
        if q[0] == '1':
            pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1]))
            pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1]))
            S[int(q[1])-1] = q[2]
        else:
            print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0])) resolve input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():

    class BinaryIndexedTree():
        def __init__(self, n):
            self.n = n
            self.bit = [0]*(n+1)

        def add(self, item, pos):
            index = pos
            while index < self.n+1:
                self.bit[index] += item
                index += index & (-index)

        def sum(self, pos):
            ret = 0
            index = pos
            while index > 0:
                ret += self.bit[index]
                index -= index & -index
            return ret

    N = int(input())
    S = list(input())
    Q = int(input())
    Query = [input().split() for _ in range(Q)] 

    pos_bit_list = [BinaryIndexedTree(len(S)) for _ in range(26)]

    for i, c in enumerate(S):
        pos_bit_list[ord(c)-ord('a')].add(1, i+1)

    for q in Query:
        if q[0] == '1':
            pos_bit_list[ord(S[int(q[1])-1])-ord('a')].add(-1, int(q[1]))
            pos_bit_list[ord(q[2])-ord('a')].add(1, int(q[1]))
            S[int(q[1])-1] = q[2]
        else:
            print(len([p for p in pos_bit_list if p.sum(int(q[2])) - p.sum(int(q[1])-1) > 0]))

if __name__ == '__main__':
    resolve()
