class my_segment_tree:

    def __init__(self, base_array, size, f=lambda a, b: a + b, default_value = 0):

        self.f = f

        self._seg_size = 2 ** (size.bit_length() + 1) - 1

        self._default_value = default_value

        self._array = [default_value] * (self._seg_size)

        k = 2 ** size.bit_length() - 1  # 一番下の最初のindex



        for i in range(size):

            self._array[k + i] = base_array[i]



        while k > 0:

            for i in range((k + 1) // 2):

                self._array[(k + 2 * i) // 2] = f(self._array[k + 2 * i], self._array[k + 2 * i + 1])

            k //= 2

    def update(self, i, v):

        i += (self._seg_size // 2)

        self._array[i] = v

        while i > 0:

            i = (i - 1) >> 1

            self._array[i] = self.f(self._array[2 * i + 1], self._array[2 * i + 2])



    def get(self, left, right):

        return self._get(left, right, 0, self._seg_size // 2, 0) #どちらも閉空間



    def _get(self, left, right, l, r, i):

        if left <= l and r <= right:

            return self._array[i]



        a = 0

        if left <= (l + r) // 2:

            a = self._get(left, min(right, (l + r) // 2), l, (l + r) // 2, 2 * i + 1)

        b = 0

        if (l + r) // 2 + 1 <= right:

            b= self._get(max(left, (l + r) // 2 + 1), right, (l + r) // 2 + 1, r, 2 * i + 2)



        return self.f(a, b)



def main():

    N = int(eval(input()))

    S = eval(input())

    M = int(eval(input()))

    A = [0 for i in range(N)]



    for i, c in enumerate(S):

        A[i] = 1 << ord(c) - ord('a')



    st = my_segment_tree(A, N, lambda a, b: a | b)



    for i in range(M):

        p, a, b = input().split()

        a  = int(a) - 1

        if p == '1':

            st.update(a, 1 << (ord(b) - ord('a')))



        if p == '2':

            s = st.get(a, int(b) - 1)

            print((bin(s).count('1')))





if __name__ == '__main__':

    main()


class SegmentTree:

    def __init__(self, base_array,n , default_value = 0, segfunc = lambda a, b: a + b): #元配列、大きさ、デフォルト値

        self._num = 2 ** (n - 1).bit_length()

        self._seg = [default_value] * 2 * self._num

        self._segfunc = segfunc

        self._ide_ele = default_value

        for i in range(n):

            self._seg[i + self._num - 1] = base_array[i]

        for i in range(self._num - 2, -1, -1):

            self._seg[i] = segfunc(self._seg[2 * i + 1], self._seg[2 * i + 2])





    def update(self, k, x):

        k += self._num - 1

        self._seg[k] = x

        while k:

            k = (k - 1) // 2

            self._seg[k] = self._segfunc(self._seg[k * 2 + 1], self._seg[k * 2 + 2])





    def query(self, p, q):

        if q <= p:

            return self._ide_ele

        p += self._num - 1

        q += self._num - 2

        res = self._ide_ele

        while q - p > 1:

            if p & 1 == 0:

                res = self._segfunc(res, self._seg[p])

            if q & 1 == 1:

                res = self._segfunc(res, self._seg[q])

                q -= 1

            p = p // 2

            q = (q - 1) // 2

        if p == q:

            res = self._segfunc(res, self._seg[p])

        else:

            res = self._segfunc(self._segfunc(res, self._seg[p]), self._seg[q])

        return res



def main():

    N = int(eval(input()))

    S = [c for c in eval(input())]

    M = int(eval(input()))



    A = [0 for i in range(N)]



    for i, c in enumerate(S):

        A[i] = 1 << ord(c) - ord('a')



    st = SegmentTree(A, N, 0, lambda a, b: a | b)



    for i in range(M):

        p, a, b = input().split()

        a  = int(a) - 1

        b = int(b) - 1 if p == '2' else b

        if p == '1':

            st.update(a, 1 << ord(b) - ord('a'))



        if p == '2':

            s = st.query(a, b + 1)

            print((bin(s).count('1')))





if __name__ == '__main__':

    main()
class my_segment_tree:
    def __init__(self, base_array, size, f=lambda a, b: a + b, default_value=0):
        self.f = f
        self._seg_size = 2 ** (size.bit_length() + 1) - 1
        self._default_value = default_value
        self._array = [default_value] * (self._seg_size)
        k = 2 ** size.bit_length() - 1  # 一番下の最初のindex
        for i in range(size):
            self._array[k + i] = base_array[i]
        while k > 0:
            for i in range((k + 1) // 2):
                self._array[(k + 2 * i) // 2] = f(
                    self._array[k + 2 * i], self._array[k + 2 * i + 1]
                )
            k //= 2

    def update(self, i, v):
        i += self._seg_size // 2
        self._array[i] = v
        while i > 0:
            i = (i - 1) >> 1
            self._array[i] = self.f(self._array[2 * i + 1], self._array[2 * i + 2])

    def get(self, left, right):
        return self._get(left, right, 0, self._seg_size // 2, 0)  # どちらも閉空間

    def _get(self, left, right, l, r, i):
        if left <= l and r <= right:
            return self._array[i]
        a = 0
        if left <= (l + r) // 2:
            a = self._get(left, min(right, (l + r) // 2), l, (l + r) // 2, 2 * i + 1)
        b = 0
        if (l + r) // 2 + 1 <= right:
            b = self._get(
                max(left, (l + r) // 2 + 1), right, (l + r) // 2 + 1, r, 2 * i + 2
            )
        return self.f(a, b)


def main():
    N = int(eval(input()))
    S = eval(input())
    M = int(eval(input()))
    A = [0 for i in range(N)]
    for i, c in enumerate(S):
        A[i] = 1 << ord(c) - ord("a")
    st = my_segment_tree(A, N, lambda a, b: a | b)
    for i in range(M):
        p, a, b = input().split()
        a = int(a) - 1
        if p == "1":
            st.update(a, 1 << (ord(b) - ord("a")))
        if p == "2":
            s = st.get(a, int(b) - 1)
            print((bin(s).count("1")))


if __name__ == "__main__":
    main()

class SegmentTree:
    def __init__(
        self, base_array, n, default_value=0, segfunc=lambda a, b: a + b
    ):  # 元配列、大きさ、デフォルト値
        self._num = 2 ** (n - 1).bit_length()
        self._seg = [default_value] * 2 * self._num
        self._segfunc = segfunc
        self._ide_ele = default_value
        for i in range(n):
            self._seg[i + self._num - 1] = base_array[i]
        for i in range(self._num - 2, -1, -1):
            self._seg[i] = segfunc(self._seg[2 * i + 1], self._seg[2 * i + 2])

    def update(self, k, x):
        k += self._num - 1
        self._seg[k] = x
        while k:
            k = (k - 1) // 2
            self._seg[k] = self._segfunc(self._seg[k * 2 + 1], self._seg[k * 2 + 2])

    def query(self, p, q):
        if q <= p:
            return self._ide_ele
        p += self._num - 1
        q += self._num - 2
        res = self._ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self._segfunc(res, self._seg[p])
            if q & 1 == 1:
                res = self._segfunc(res, self._seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self._segfunc(res, self._seg[p])
        else:
            res = self._segfunc(self._segfunc(res, self._seg[p]), self._seg[q])
        return res


def main():
    N = int(eval(input()))
    S = [c for c in eval(input())]
    M = int(eval(input()))
    A = [0 for i in range(N)]
    for i, c in enumerate(S):
        A[i] = 1 << ord(c) - ord("a")
    st = SegmentTree(A, N, 0, lambda a, b: a | b)
    for i in range(M):
        p, a, b = input().split()
        a = int(a) - 1
        b = int(b) - 1 if p == "2" else b
        if p == "1":
            st.update(a, 1 << ord(b) - ord("a"))
        if p == "2":
            s = st.query(a, b + 1)
            print((bin(s).count("1")))


if __name__ == "__main__":
    main()

-class my_segment_tree: -    def __init__(self, base_array, size, f=lambda a, b: a + b, default_value=0): -        self.f = f -        self._seg_size = 2 ** (size.bit_length() + 1) - 1 -        self._default_value = default_value -        self._array = [default_value] * (self._seg_size) -        k = 2 ** size.bit_length() - 1  # 一番下の最初のindex -        for i in range(size): -            self._array[k + i] = base_array[i] -        while k > 0: -            for i in range((k + 1) // 2): -                self._array[(k + 2 * i) // 2] = f( -                    self._array[k + 2 * i], self._array[k + 2 * i + 1] -                ) -            k //= 2 +class SegmentTree: +    def __init__( +        self, base_array, n, default_value=0, segfunc=lambda a, b: a + b +    ):  # 元配列、大きさ、デフォルト値 +        self._num = 2 ** (n - 1).bit_length() +        self._seg = [default_value] * 2 * self._num +        self._segfunc = segfunc +        self._ide_ele = default_value +        for i in range(n): +            self._seg[i + self._num - 1] = base_array[i] +        for i in range(self._num - 2, -1, -1): +            self._seg[i] = segfunc(self._seg[2 * i + 1], self._seg[2 * i + 2]) -    def update(self, i, v): -        i += self._seg_size // 2 -        self._array[i] = v -        while i > 0: -            i = (i - 1) >> 1 -            self._array[i] = self.f(self._array[2 * i + 1], self._array[2 * i + 2]) +    def update(self, k, x): +        k += self._num - 1 +        self._seg[k] = x +        while k: +            k = (k - 1) // 2 +            self._seg[k] = self._segfunc(self._seg[k * 2 + 1], self._seg[k * 2 + 2]) -    def get(self, left, right): -        return self._get(left, right, 0, self._seg_size // 2, 0)  # どちらも閉空間 - -    def _get(self, left, right, l, r, i): -        if left <= l and r <= right: -            return self._array[i] -        a = 0 -        if left <= (l + r) // 2: -            a = self._get(left, min(right, (l + r) // 2), l, (l + r) // 2, 2 * i + 1) -        b = 0 -        if (l + r) // 2 + 1 <= right: -            b = self._get( -                max(left, (l + r) // 2 + 1), right, (l + r) // 2 + 1, r, 2 * i + 2 -            ) -        return self.f(a, b) +    def query(self, p, q): +        if q <= p: +            return self._ide_ele +        p += self._num - 1 +        q += self._num - 2 +        res = self._ide_ele +        while q - p > 1: +            if p & 1 == 0: +                res = self._segfunc(res, self._seg[p]) +            if q & 1 == 1: +                res = self._segfunc(res, self._seg[q]) +                q -= 1 +            p = p // 2 +            q = (q - 1) // 2 +        if p == q: +            res = self._segfunc(res, self._seg[p]) +        else: +            res = self._segfunc(self._segfunc(res, self._seg[p]), self._seg[q]) +        return res -    S = eval(input()) +    S = [c for c in eval(input())] -    st = my_segment_tree(A, N, lambda a, b: a | b) +    st = SegmentTree(A, N, 0, lambda a, b: a | b) +        b = int(b) - 1 if p == "2" else b -            st.update(a, 1 << (ord(b) - ord("a"))) +            st.update(a, 1 << ord(b) - ord("a")) -            s = st.get(a, int(b) - 1) +            s = st.query(a, b + 1)