
import operator
class SegmentTree:
    def __init__(self, size, fn=operator.add, default=None, initial_values=None):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        :param default:
        :param list initial_values:
        """
        default = default or 0

        # size 以上である最小の 2 冪を size とする
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._fn = fn

        self._tree = [default] * (self._size * 2 - 1)
        if initial_values:
            i = self._size - 1
            for v in initial_values:
                self._tree[i] = v
                i += 1
            i = self._size - 2
            while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

    def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

    def add(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

    def get(self, from_i, to_i=None, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        if to_i is None:
            return self._tree[self._size - 1 + from_i]

        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

    def __len__(self):
        return self._size

def resolve():
    N = int(input())
    S = input()
    Q = int(input())

    seg = SegmentTree(N, fn=operator.or_)
    for i in range(N):
        s = 2 ** (ord(S[i]) - ord('a'))
        seg.set(i, s)

    for _ in range(Q):
        act, q1, q2 = input().split()
        if act == "1":
            # 文字変更
            idx = int(q1) - 1
            s_bin = 1 << (ord(q2) - ord('a'))
            seg.set(idx, s_bin)
        else:
            # L,R区間の文字種を出力
            l = int(q1)-1
            r = int(q2)
            x = bin(seg.get(l, r))
            print(x.count("1"))


if __name__ == "__main__":
    resolve() import operator operator class SegmentTree:
    def __init__(self, size, fn=operator.add, default=None, initial_values=None):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        :param default:
        :param list initial_values:
        """
        default = default or 0

        # size 以上である最小の 2 冪を size とする
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._fn = fn

        self._tree = [default] * (self._size * 2 - 1)
        if initial_values:
            i = self._size - 1
            for v in initial_values:
                self._tree[i] = v
                i += 1
            i = self._size - 2
            while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

    def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

    def add(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

    def get(self, from_i, to_i=None, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        if to_i is None:
            return self._tree[self._size - 1 + from_i]

        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

    def __len__(self):
        return self._size SegmentTree def __init__(self, size, fn=operator.add, default=None, initial_values=None):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        :param default:
        :param list initial_values:
        """
        default = default or 0

        # size 以上である最小の 2 冪を size とする
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._fn = fn

        self._tree = [default] * (self._size * 2 - 1)
        if initial_values:
            i = self._size - 1
            for v in initial_values:
                self._tree[i] = v
                i += 1
            i = self._size - 2
            while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

     __init__ """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        :param default:
        :param list initial_values:
        """ default = default or 0 default default or 0 default 0 n = 1 n 1 while n < size:
            n *= 2
         n < size n size n *= 2 n 2 self._size = n self._size self _size n self._fn = fn self._fn self _fn fn self._tree = [default] * (self._size * 2 - 1) self._tree self _tree [default] * (self._size * 2 - 1) [default] default self._size * 2 - 1 self._size * 2 self._size self _size 2 1 if initial_values:
            i = self._size - 1
            for v in initial_values:
                self._tree[i] = v
                i += 1
            i = self._size - 2
            while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

     initial_values i = self._size - 1 i self._size - 1 self._size self _size 1 for v in initial_values:
                self._tree[i] = v
                i += 1
             v initial_values self._tree[i] = v self._tree[i] self._tree self _tree i v i += 1 i 1 i = self._size - 2 i self._size - 2 self._size self _size 2 while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

     i >= 0 i 0 self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2]) self._tree[i] self._tree self _tree i self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2]) self._fn self _fn self._tree[i * 2 + 1] self._tree self _tree i * 2 + 1 i * 2 i 2 1 self._tree[i * 2 + 2] self._tree self _tree i * 2 + 2 i * 2 i 2 2 i -= 1 i 1 self self size size fn=operator.add fn operator.add operator add default=None default None initial_values=None initial_values None def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

     set """
        i 番目に value を設定
        :param int i:
        :param value:
        :return:
        """ x = self._size - 1 + i x self._size - 1 + i self._size - 1 self._size self _size 1 i self._tree[x] = value self._tree[x] self._tree self _tree x value while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

     x > 0 x 0 x = (x - 1) // 2 x (x - 1) // 2 x - 1 x 1 2 self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2]) self._tree[x] self._tree self _tree x self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2]) self._fn self _fn self._tree[x * 2 + 1] self._tree self _tree x * 2 + 1 x * 2 x 2 1 self._tree[x * 2 + 2] self._tree self _tree x * 2 + 2 x * 2 x 2 2 self self i i value value def add(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

     add """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param value:
        :return:
        """ x = self._size - 1 + i x self._size - 1 + i self._size - 1 self._size self _size 1 i self.set(i, self._fn(self._tree[x], value)) self.set self set i self._fn(self._tree[x], value) self._fn self _fn self._tree[x] self._tree self _tree x value self self i i value value def get(self, from_i, to_i=None, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        if to_i is None:
            return self._tree[self._size - 1 + from_i]

        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

     get """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """ if to_i is None:
            return self._tree[self._size - 1 + from_i]

         to_i is None to_i None return self._tree[self._size - 1 + from_i] self._tree[self._size - 1 + from_i] self._tree self _tree self._size - 1 + from_i self._size - 1 self._size self _size 1 from_i L = 0 if L is None else L L 0 if L is None else L L is None L None 0 L r = self._size if r is None else r r self._size if r is None else r r is None r None self._size self _size r if from_i <= L and r <= to_i:
            return self._tree[k]

         from_i <= L and r <= to_i from_i <= L from_i L r <= to_i r to_i return self._tree[k] self._tree[k] self._tree self _tree k if to_i <= L or r <= from_i:
            return None

         to_i <= L or r <= from_i to_i <= L to_i L r <= from_i r from_i return None None ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2) ret_L self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2) self.get self get from_i to_i k * 2 + 1 k * 2 k 2 1 L (L + r) // 2 L + r L r 2 ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r) ret_r self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r) self.get self get from_i to_i k * 2 + 2 k * 2 k 2 2 (L + r) // 2 L + r L r 2 r if ret_L is None:
            return ret_r
         ret_L is None ret_L None return ret_r ret_r if ret_r is None:
            return ret_L
         ret_r is None ret_r None return ret_L ret_L return self._fn(ret_L, ret_r) self._fn(ret_L, ret_r) self._fn self _fn ret_L ret_r self self from_i from_i to_i=None to_i None k=0 k 0 L=None L None r=None r None def __len__(self):
        return self._size __len__ return self._size self._size self _size self self def resolve():
    N = int(input())
    S = input()
    Q = int(input())

    seg = SegmentTree(N, fn=operator.or_)
    for i in range(N):
        s = 2 ** (ord(S[i]) - ord('a'))
        seg.set(i, s)

    for _ in range(Q):
        act, q1, q2 = input().split()
        if act == "1":
            # 文字変更
            idx = int(q1) - 1
            s_bin = 1 << (ord(q2) - ord('a'))
            seg.set(idx, s_bin)
        else:
            # L,R区間の文字種を出力
            l = int(q1)-1
            r = int(q2)
            x = bin(seg.get(l, r))
            print(x.count("1")) resolve N = int(input()) N int(input()) int input() input S = input() S input() input Q = int(input()) Q int(input()) int input() input seg = SegmentTree(N, fn=operator.or_) seg SegmentTree(N, fn=operator.or_) SegmentTree N fn=operator.or_ fn operator.or_ operator or_ for i in range(N):
        s = 2 ** (ord(S[i]) - ord('a'))
        seg.set(i, s)

     i range(N) range N s = 2 ** (ord(S[i]) - ord('a')) s 2 ** (ord(S[i]) - ord('a')) 2 ord(S[i]) - ord('a') ord(S[i]) ord S[i] S i ord('a') ord 'a' seg.set(i, s) seg.set seg set i s for _ in range(Q):
        act, q1, q2 = input().split()
        if act == "1":
            # 文字変更
            idx = int(q1) - 1
            s_bin = 1 << (ord(q2) - ord('a'))
            seg.set(idx, s_bin)
        else:
            # L,R区間の文字種を出力
            l = int(q1)-1
            r = int(q2)
            x = bin(seg.get(l, r))
            print(x.count("1")) _ range(Q) range Q act, q1, q2 = input().split() act input().split() ().split () input split q1 q2 if act == "1":
            # 文字変更
            idx = int(q1) - 1
            s_bin = 1 << (ord(q2) - ord('a'))
            seg.set(idx, s_bin)
        else:
            # L,R区間の文字種を出力
            l = int(q1)-1
            r = int(q2)
            x = bin(seg.get(l, r))
            print(x.count("1")) act == "1" act "1" idx = int(q1) - 1 idx int(q1) - 1 int(q1) int q1 1 s_bin = 1 << (ord(q2) - ord('a')) s_bin 1 << (ord(q2) - ord('a')) 1 ord(q2) - ord('a') ord(q2) ord q2 ord('a') ord 'a' seg.set(idx, s_bin) seg.set seg set idx s_bin l = int(q1)-1 l int(q1)-1 int(q1) int q1 1 r = int(q2) r int(q2) int q2 x = bin(seg.get(l, r)) x bin(seg.get(l, r)) bin seg.get(l, r) seg.get seg get l r print(x.count("1")) print x.count("1") x.count x count "1" if __name__ == "__main__":
    resolve() __name__ == "__main__" __name__ "__main__" resolve() resolve def resolve():
    N = int(input())
    S = input()
    Q = int(input())

    seg = SegmentTree(N, fn=operator.or_)
    for i in range(N):
        s = 2 ** (ord(S[i]) - ord('a'))
        seg.set(i, s)

    for _ in range(Q):
        act, q1, q2 = input().split()
        if act == "1":
            # 文字変更
            idx = int(q1) - 1
            s_bin = 1 << (ord(q2) - ord('a'))
            seg.set(idx, s_bin)
        else:
            # L,R区間の文字種を出力
            l = int(q1)-1
            r = int(q2)
            x = bin(seg.get(l, r))
            print(x.count("1")) def resolve():
    N = int(input())
    S = input()
    Q = int(input())

    seg = SegmentTree(N, fn=operator.or_)
    for i in range(N):
        s = 2 ** (ord(S[i]) - ord('a'))
        seg.set(i, s)

    for _ in range(Q):
        act, q1, q2 = input().split()
        if act == "1":
            # 文字変更
            idx = int(q1) - 1
            s_bin = 1 << (ord(q2) - ord('a'))
            seg.set(idx, s_bin)
        else:
            # L,R区間の文字種を出力
            l = int(q1)-1
            r = int(q2)
            x = bin(seg.get(l, r))
            print(x.count("1")) resolve class SegmentTree:
    def __init__(self, size, fn=operator.add, default=None, initial_values=None):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        :param default:
        :param list initial_values:
        """
        default = default or 0

        # size 以上である最小の 2 冪を size とする
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._fn = fn

        self._tree = [default] * (self._size * 2 - 1)
        if initial_values:
            i = self._size - 1
            for v in initial_values:
                self._tree[i] = v
                i += 1
            i = self._size - 2
            while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

    def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

    def add(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

    def get(self, from_i, to_i=None, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        if to_i is None:
            return self._tree[self._size - 1 + from_i]

        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

    def __len__(self):
        return self._size class SegmentTree:
    def __init__(self, size, fn=operator.add, default=None, initial_values=None):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        :param default:
        :param list initial_values:
        """
        default = default or 0

        # size 以上である最小の 2 冪を size とする
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._fn = fn

        self._tree = [default] * (self._size * 2 - 1)
        if initial_values:
            i = self._size - 1
            for v in initial_values:
                self._tree[i] = v
                i += 1
            i = self._size - 2
            while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

    def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

    def add(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

    def get(self, from_i, to_i=None, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        if to_i is None:
            return self._tree[self._size - 1 + from_i]

        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

    def __len__(self):
        return self._size SegmentTree

import operator
class SegmentTree:
    def __init__(self, size, fn=operator.add, default=None, initial_values=None):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        :param default:
        :param list initial_values:
        """
        default = default or 0

        # size 以上である最小の 2 冪を size とする
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._fn = fn

        self._tree = [default] * (self._size * 2 - 1)
        if initial_values:
            i = self._size - 1
            for v in initial_values:
                self._tree[i] = v
                i += 1
            i = self._size - 2
            while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

    def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

    def add(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

    def get(self, from_i, to_i=None, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        if to_i is None:
            return self._tree[self._size - 1 + from_i]

        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

    def __len__(self):
        return self._size

def resolve():
    N = int(input())
    S = input()
    Q = int(input())

    seg = SegmentTree(N, fn=operator.or_)
    for i in range(N):
        s = 2 ** (ord(S[i]) - ord('a'))
        seg.set(i, s)

    for _ in range(Q):
        act, q1, q2 = input().split()
        if act == "1":
            # 文字変更
            idx = int(q1) - 1
            s_bin = 1 << (ord(q2) - ord('a'))
            seg.set(idx, s_bin)
        else:
            # L,R区間の文字種を出力
            l = int(q1)-1
            r = int(q2)
            x = bin(seg.get(l, r))
            print(x.count("1"))


if __name__ == "__main__":
    resolve()
