class BalancingTree:
    """平衡二分木のクラス
    Pivotを使った実装.
    0以上2^n - 2以下の整数を扱う
    """
    def __init__(self, n):
        """
        2の指数nで初期化
        """
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    def debug(self):
        """デバッグ用の関数"""
        def debug_info(nd_):
            return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1)

        def debug_node(nd):
            re = []
            if nd.left:
                re += debug_node(nd.left)
            if nd.value: re.append(debug_info(nd))
            if nd.right:
                re += debug_node(nd.right)
            return re
        print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50])

    def append(self, v):
        """
        v を追加（その時点で v はない前提）
        """
        v += 1
        nd = self.root
        while True:
            if v == nd.value:
                # v がすでに存在する場合に何か処理が必要ならここに書く
                return 0
            else:
                mi, ma = min(v, nd.value), max(v, nd.value)
                if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

    def leftmost(self, nd):
        if nd.left: return self.leftmost(nd.left)
        return nd

    def rightmost(self, nd):
        if nd.right: return self.rightmost(nd.right)
        return nd

    def find_l(self, v):
        """
        vより真に小さいやつの中での最大値（なければ-1）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value < v: prev = nd.value
        while True:
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                prev = nd.value
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    def find_r(self, v):
        """
        vより真に大きいやつの中での最小値（なければRoot）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value > v: prev = nd.value
        while True:
            if v < nd.value:
                prev = nd.value
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    @property
    def max(self):
        """最大値の属性"""
        return self.find_l((1<<self.N)-1)

    @property
    def min(self):
        """最小値の属性"""
        return self.find_r(-1)

    def delete(self, v, nd = None, prev = None):
        """
        値がvのノードがあれば削除（なければ何もしない）
        """
        v += 1
        if not nd: nd = self.root
        if not prev: prev = nd
        while v != nd.value:
            prev = nd
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return
        if (not nd.left) and (not nd.right):
            if nd.value < prev.value:
                prev.left = None
            else:
                prev.right = None
        elif not nd.left:
            if nd.value < prev.value:
                prev.left = nd.right
            else:
                prev.right = nd.right
        elif not nd.right:
            if nd.value < prev.value:
                prev.left = nd.left
            else:
                prev.right = nd.left
        else:
            nd.value = self.leftmost(nd.right).value
            self.delete(nd.value - 1, nd.right, nd)

    def __contains__(self, v: int) -> bool:
        return self.find_r(v - 1) == v

    class node:
        """ノードをあらわすクラス
        v: 値
        p: ピボット値
        で初期化
        """
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None

Trees = [BalancingTree(50) for _ in range(26)]
N = int(input())
S = input()
Q = int(input())
alphabets = list("abcdefghijklmnopqrstuvwxyz")
c2n = {c: i for i, c in enumerate(alphabets)}
for i in range(N):
    Trees[c2n[S[i]]].append(i+1)
S = list(S)
for _ in range(Q):
    tmp = list(input().split())
    if tmp[0] == "1":
        _, i, c = tmp
        i = int(i)
        bef = S[i-1]
        if bef == c:
            continue
        Trees[c2n[bef]].delete(i)
        Trees[c2n[c]].append(i)
        S[i-1] = c
    else:
        _, l, r = tmp
        l = int(l)
        r = int(r)
        ans = 0
        for char in range(26):
            res = Trees[char].find_r(l-1)
            if l <= res <= r:
                ans += 1
        print(ans) class BalancingTree:
    """平衡二分木のクラス
    Pivotを使った実装.
    0以上2^n - 2以下の整数を扱う
    """
    def __init__(self, n):
        """
        2の指数nで初期化
        """
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    def debug(self):
        """デバッグ用の関数"""
        def debug_info(nd_):
            return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1)

        def debug_node(nd):
            re = []
            if nd.left:
                re += debug_node(nd.left)
            if nd.value: re.append(debug_info(nd))
            if nd.right:
                re += debug_node(nd.right)
            return re
        print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50])

    def append(self, v):
        """
        v を追加（その時点で v はない前提）
        """
        v += 1
        nd = self.root
        while True:
            if v == nd.value:
                # v がすでに存在する場合に何か処理が必要ならここに書く
                return 0
            else:
                mi, ma = min(v, nd.value), max(v, nd.value)
                if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

    def leftmost(self, nd):
        if nd.left: return self.leftmost(nd.left)
        return nd

    def rightmost(self, nd):
        if nd.right: return self.rightmost(nd.right)
        return nd

    def find_l(self, v):
        """
        vより真に小さいやつの中での最大値（なければ-1）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value < v: prev = nd.value
        while True:
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                prev = nd.value
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    def find_r(self, v):
        """
        vより真に大きいやつの中での最小値（なければRoot）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value > v: prev = nd.value
        while True:
            if v < nd.value:
                prev = nd.value
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    @property
    def max(self):
        """最大値の属性"""
        return self.find_l((1<<self.N)-1)

    @property
    def min(self):
        """最小値の属性"""
        return self.find_r(-1)

    def delete(self, v, nd = None, prev = None):
        """
        値がvのノードがあれば削除（なければ何もしない）
        """
        v += 1
        if not nd: nd = self.root
        if not prev: prev = nd
        while v != nd.value:
            prev = nd
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return
        if (not nd.left) and (not nd.right):
            if nd.value < prev.value:
                prev.left = None
            else:
                prev.right = None
        elif not nd.left:
            if nd.value < prev.value:
                prev.left = nd.right
            else:
                prev.right = nd.right
        elif not nd.right:
            if nd.value < prev.value:
                prev.left = nd.left
            else:
                prev.right = nd.left
        else:
            nd.value = self.leftmost(nd.right).value
            self.delete(nd.value - 1, nd.right, nd)

    def __contains__(self, v: int) -> bool:
        return self.find_r(v - 1) == v

    class node:
        """ノードをあらわすクラス
        v: 値
        p: ピボット値
        で初期化
        """
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None BalancingTree """平衡二分木のクラス
    Pivotを使った実装.
    0以上2^n - 2以下の整数を扱う
    """ def __init__(self, n):
        """
        2の指数nで初期化
        """
        self.N = n
        self.root = self.node(1<<n, 1<<n)

     __init__ """
        2の指数nで初期化
        """ self.N = n self.N self N n self.root = self.node(1<<n, 1<<n) self.root self root self.node(1<<n, 1<<n) self.node self node 1<<n 1 n 1<<n 1 n self self n n def debug(self):
        """デバッグ用の関数"""
        def debug_info(nd_):
            return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1)

        def debug_node(nd):
            re = []
            if nd.left:
                re += debug_node(nd.left)
            if nd.value: re.append(debug_info(nd))
            if nd.right:
                re += debug_node(nd.right)
            return re
        print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50])

     debug """デバッグ用の関数""" def debug_info(nd_):
            return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1)

         debug_info return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1) (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1) nd_.value - 1 nd_.value nd_ value 1 nd_.pivot - 1 nd_.pivot nd_ pivot 1 nd_.left.value - 1 if nd_.left else -1 nd_.left nd_ left nd_.left.value - 1 nd_.left.value nd_.left nd_ left value 1 -1 nd_.right.value - 1 if nd_.right else -1 nd_.right nd_ right nd_.right.value - 1 nd_.right.value nd_.right nd_ right value 1 -1 nd_ nd_ def debug_node(nd):
            re = []
            if nd.left:
                re += debug_node(nd.left)
            if nd.value: re.append(debug_info(nd))
            if nd.right:
                re += debug_node(nd.right)
            return re
         debug_node re = [] re [] if nd.left:
                re += debug_node(nd.left)
             nd.left nd left re += debug_node(nd.left) re debug_node(nd.left) debug_node nd.left nd left if nd.value: re.append(debug_info(nd))
             nd.value nd value if nd.right:
                re += debug_node(nd.right)
             nd.right nd right re += debug_node(nd.right) re debug_node(nd.right) debug_node nd.right nd right return re re nd nd print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50]) print "Debug - root =" self.root.value - 1 self.root.value self.root self root value 1 debug_node(self.root)[:50] (self.root) debug_node self.root self root :50 50 self self def append(self, v):
        """
        v を追加（その時点で v はない前提）
        """
        v += 1
        nd = self.root
        while True:
            if v == nd.value:
                # v がすでに存在する場合に何か処理が必要ならここに書く
                return 0
            else:
                mi, ma = min(v, nd.value), max(v, nd.value)
                if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

     append """
        v を追加（その時点で v はない前提）
        """ v += 1 v 1 nd = self.root nd self.root self root while True:
            if v == nd.value:
                # v がすでに存在する場合に何か処理が必要ならここに書く
                return 0
            else:
                mi, ma = min(v, nd.value), max(v, nd.value)
                if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

     True if v == nd.value:
                # v がすでに存在する場合に何か処理が必要ならここに書く
                return 0
            else:
                mi, ma = min(v, nd.value), max(v, nd.value)
                if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

     v == nd.value v nd.value nd value return 0 0 mi, ma = min(v, nd.value), max(v, nd.value) mi min(v, nd.value) min v nd.value nd value ma max(v, nd.value) max v nd.value nd value if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

     mi < nd.pivot mi nd.pivot nd pivot nd.value = ma nd.value nd value ma if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                 nd.left nd left nd = nd.left nd nd.left nd left v = mi v mi p = nd.pivot p nd.pivot nd pivot nd.left = self.node(mi, p - (p&-p)//2) nd.left nd left self.node(mi, p - (p&-p)//2) self.node self node mi p - (p&-p)//2 p (p&-p)//2 p&-p p -p p 2 break nd.value = mi nd.value nd value mi if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

     nd.right nd right nd = nd.right nd nd.right nd right v = ma v ma p = nd.pivot p nd.pivot nd pivot nd.right = self.node(ma, p + (p&-p)//2) nd.right nd right self.node(ma, p + (p&-p)//2) self.node self node ma p + (p&-p)//2 p (p&-p)//2 p&-p p -p p 2 break self self v v def leftmost(self, nd):
        if nd.left: return self.leftmost(nd.left)
        return nd

     leftmost if nd.left: return self.leftmost(nd.left)
         nd.left nd left return nd nd self self nd nd def rightmost(self, nd):
        if nd.right: return self.rightmost(nd.right)
        return nd

     rightmost if nd.right: return self.rightmost(nd.right)
         nd.right nd right return nd nd self self nd nd def find_l(self, v):
        """
        vより真に小さいやつの中での最大値（なければ-1）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value < v: prev = nd.value
        while True:
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                prev = nd.value
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

     find_l """
        vより真に小さいやつの中での最大値（なければ-1）
        """ v += 1 v 1 nd = self.root nd self.root self root prev = 0 prev 0 if nd.value < v: prev = nd.value
         nd.value < v nd.value nd value v while True:
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                prev = nd.value
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

     True if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                prev = nd.value
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

     v <= nd.value v nd.value nd value if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
             nd.left nd left nd = nd.left nd nd.left nd left return prev - 1 prev - 1 prev 1 prev = nd.value prev nd.value nd value if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

     nd.right nd right nd = nd.right nd nd.right nd right return prev - 1 prev - 1 prev 1 self self v v def find_r(self, v):
        """
        vより真に大きいやつの中での最小値（なければRoot）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value > v: prev = nd.value
        while True:
            if v < nd.value:
                prev = nd.value
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

     find_r """
        vより真に大きいやつの中での最小値（なければRoot）
        """ v += 1 v 1 nd = self.root nd self.root self root prev = 0 prev 0 if nd.value > v: prev = nd.value
         nd.value > v nd.value nd value v while True:
            if v < nd.value:
                prev = nd.value
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

     True if v < nd.value:
                prev = nd.value
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

     v < nd.value v nd.value nd value prev = nd.value prev nd.value nd value if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
             nd.left nd left nd = nd.left nd nd.left nd left return prev - 1 prev - 1 prev 1 if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

     nd.right nd right nd = nd.right nd nd.right nd right return prev - 1 prev - 1 prev 1 self self v v def max(self):
        """最大値の属性"""
        return self.find_l((1<<self.N)-1)

     max """最大値の属性""" return self.find_l((1<<self.N)-1) self.find_l((1<<self.N)-1) self.find_l self find_l (1<<self.N)-1 1<<self.N 1 self.N self N 1 self self @property
     max property max def min(self):
        """最小値の属性"""
        return self.find_r(-1)

     min """最小値の属性""" return self.find_r(-1) self.find_r(-1) self.find_r self find_r -1 self self @property
     min property min def delete(self, v, nd = None, prev = None):
        """
        値がvのノードがあれば削除（なければ何もしない）
        """
        v += 1
        if not nd: nd = self.root
        if not prev: prev = nd
        while v != nd.value:
            prev = nd
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return
        if (not nd.left) and (not nd.right):
            if nd.value < prev.value:
                prev.left = None
            else:
                prev.right = None
        elif not nd.left:
            if nd.value < prev.value:
                prev.left = nd.right
            else:
                prev.right = nd.right
        elif not nd.right:
            if nd.value < prev.value:
                prev.left = nd.left
            else:
                prev.right = nd.left
        else:
            nd.value = self.leftmost(nd.right).value
            self.delete(nd.value - 1, nd.right, nd)

     delete """
        値がvのノードがあれば削除（なければ何もしない）
        """ v += 1 v 1 if not nd: nd = self.root
         not nd nd if not prev: prev = nd
         not prev prev while v != nd.value:
            prev = nd
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return
         v != nd.value v nd.value nd value prev = nd prev nd if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return
         v <= nd.value v nd.value nd value if nd.left:
                    nd = nd.left
                else:
                    return
             nd.left nd left nd = nd.left nd nd.left nd left return if nd.right:
                    nd = nd.right
                else:
                    return
         nd.right nd right nd = nd.right nd nd.right nd right return if (not nd.left) and (not nd.right):
            if nd.value < prev.value:
                prev.left = None
            else:
                prev.right = None
        elif not nd.left:
            if nd.value < prev.value:
                prev.left = nd.right
            else:
                prev.right = nd.right
        elif not nd.right:
            if nd.value < prev.value:
                prev.left = nd.left
            else:
                prev.right = nd.left
        else:
            nd.value = self.leftmost(nd.right).value
            self.delete(nd.value - 1, nd.right, nd)

     (not nd.left) and (not nd.right) not nd.left nd.left nd left not nd.right nd.right nd right if nd.value < prev.value:
                prev.left = None
            else:
                prev.right = None
         nd.value < prev.value nd.value nd value prev.value prev value prev.left = None prev.left prev left None prev.right = None prev.right prev right None elif not nd.left:
            if nd.value < prev.value:
                prev.left = nd.right
            else:
                prev.right = nd.right
         not nd.left nd.left nd left if nd.value < prev.value:
                prev.left = nd.right
            else:
                prev.right = nd.right
         nd.value < prev.value nd.value nd value prev.value prev value prev.left = nd.right prev.left prev left nd.right nd right prev.right = nd.right prev.right prev right nd.right nd right elif not nd.right:
            if nd.value < prev.value:
                prev.left = nd.left
            else:
                prev.right = nd.left
         not nd.right nd.right nd right if nd.value < prev.value:
                prev.left = nd.left
            else:
                prev.right = nd.left
         nd.value < prev.value nd.value nd value prev.value prev value prev.left = nd.left prev.left prev left nd.left nd left prev.right = nd.left prev.right prev right nd.left nd left nd.value = self.leftmost(nd.right).value nd.value nd value self.leftmost(nd.right).value self.leftmost(nd.right) self.leftmost self leftmost nd.right nd right value self.delete(nd.value - 1, nd.right, nd) self.delete self delete nd.value - 1 nd.value nd value 1 nd.right nd right nd self self v v nd = None nd None prev = None prev None def __contains__(self, v: int) -> bool:
        return self.find_r(v - 1) == v

     __contains__ return self.find_r(v - 1) == v self.find_r(v - 1) == v self.find_r(v - 1) self.find_r self find_r v - 1 v 1 v self self v: int v class node:
        """ノードをあらわすクラス
        v: 値
        p: ピボット値
        で初期化
        """
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None node """ノードをあらわすクラス
        v: 値
        p: ピボット値
        で初期化
        """ def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None __init__ self.value = v self.value self value v self.pivot = p self.pivot self pivot p self.left = None self.left self left None self.right = None self.right self right None self self v v p p BalancingTree(50) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BalancingTree(50) BalancingTree 50 Trees = [BalancingTree(50) for _ in range(26)] Trees [BalancingTree(50) for _ in range(26)] N = int(input()) N int(input()) int input() input S = input() S input() input Q = int(input()) Q int(input()) int input() input alphabets = list("abcdefghijklmnopqrstuvwxyz") alphabets list("abcdefghijklmnopqrstuvwxyz") list "abcdefghijklmnopqrstuvwxyz" c: i for i, c in enumerate(alphabets) for i, c in enumerate(alphabets) i c enumerate(alphabets) enumerate alphabets for i, c in enumerate(alphabets) c i c2n = {c: i for i, c in enumerate(alphabets)} c2n {c: i for i, c in enumerate(alphabets)} for i in range(N):
    Trees[c2n[S[i]]].append(i+1) i range(N) range N Trees[c2n[S[i]]].append(i+1) [c2n[S[i]]].append [c2n[S[i]]] Trees c2n[S[i]] c2n S[i] S i append i+1 i 1 S = list(S) S list(S) list S for _ in range(Q):
    tmp = list(input().split())
    if tmp[0] == "1":
        _, i, c = tmp
        i = int(i)
        bef = S[i-1]
        if bef == c:
            continue
        Trees[c2n[bef]].delete(i)
        Trees[c2n[c]].append(i)
        S[i-1] = c
    else:
        _, l, r = tmp
        l = int(l)
        r = int(r)
        ans = 0
        for char in range(26):
            res = Trees[char].find_r(l-1)
            if l <= res <= r:
                ans += 1
        print(ans) _ range(Q) range Q tmp = list(input().split()) tmp list(input().split()) list input().split() ().split () input split if tmp[0] == "1":
        _, i, c = tmp
        i = int(i)
        bef = S[i-1]
        if bef == c:
            continue
        Trees[c2n[bef]].delete(i)
        Trees[c2n[c]].append(i)
        S[i-1] = c
    else:
        _, l, r = tmp
        l = int(l)
        r = int(r)
        ans = 0
        for char in range(26):
            res = Trees[char].find_r(l-1)
            if l <= res <= r:
                ans += 1
        print(ans) tmp[0] == "1" tmp[0] tmp 0 "1" _, i, c = tmp _ tmp i c i = int(i) i int(i) int i bef = S[i-1] bef S[i-1] S i-1 i 1 if bef == c:
            continue
         bef == c bef c continue Trees[c2n[bef]].delete(i) [c2n[bef]].delete [c2n[bef]] Trees c2n[bef] c2n bef delete i Trees[c2n[c]].append(i) [c2n[c]].append [c2n[c]] Trees c2n[c] c2n c append i S[i-1] = c S[i-1] S i-1 i 1 c _, l, r = tmp _ tmp l r l = int(l) l int(l) int l r = int(r) r int(r) int r ans = 0 ans 0 for char in range(26):
            res = Trees[char].find_r(l-1)
            if l <= res <= r:
                ans += 1
         char range(26) range 26 res = Trees[char].find_r(l-1) res Trees[char].find_r(l-1) [char].find_r [char] Trees char find_r l-1 l 1 if l <= res <= r:
                ans += 1
         l <= res <= r l <= res l res r ans += 1 ans 1 print(ans) print ans i, c = tmp tmp i c = tmp tmp c _, i, c = tmp tmp _ class BalancingTree:
    """平衡二分木のクラス
    Pivotを使った実装.
    0以上2^n - 2以下の整数を扱う
    """
    def __init__(self, n):
        """
        2の指数nで初期化
        """
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    def debug(self):
        """デバッグ用の関数"""
        def debug_info(nd_):
            return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1)

        def debug_node(nd):
            re = []
            if nd.left:
                re += debug_node(nd.left)
            if nd.value: re.append(debug_info(nd))
            if nd.right:
                re += debug_node(nd.right)
            return re
        print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50])

    def append(self, v):
        """
        v を追加（その時点で v はない前提）
        """
        v += 1
        nd = self.root
        while True:
            if v == nd.value:
                # v がすでに存在する場合に何か処理が必要ならここに書く
                return 0
            else:
                mi, ma = min(v, nd.value), max(v, nd.value)
                if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

    def leftmost(self, nd):
        if nd.left: return self.leftmost(nd.left)
        return nd

    def rightmost(self, nd):
        if nd.right: return self.rightmost(nd.right)
        return nd

    def find_l(self, v):
        """
        vより真に小さいやつの中での最大値（なければ-1）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value < v: prev = nd.value
        while True:
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                prev = nd.value
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    def find_r(self, v):
        """
        vより真に大きいやつの中での最小値（なければRoot）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value > v: prev = nd.value
        while True:
            if v < nd.value:
                prev = nd.value
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    @property
    def max(self):
        """最大値の属性"""
        return self.find_l((1<<self.N)-1)

    @property
    def min(self):
        """最小値の属性"""
        return self.find_r(-1)

    def delete(self, v, nd = None, prev = None):
        """
        値がvのノードがあれば削除（なければ何もしない）
        """
        v += 1
        if not nd: nd = self.root
        if not prev: prev = nd
        while v != nd.value:
            prev = nd
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return
        if (not nd.left) and (not nd.right):
            if nd.value < prev.value:
                prev.left = None
            else:
                prev.right = None
        elif not nd.left:
            if nd.value < prev.value:
                prev.left = nd.right
            else:
                prev.right = nd.right
        elif not nd.right:
            if nd.value < prev.value:
                prev.left = nd.left
            else:
                prev.right = nd.left
        else:
            nd.value = self.leftmost(nd.right).value
            self.delete(nd.value - 1, nd.right, nd)

    def __contains__(self, v: int) -> bool:
        return self.find_r(v - 1) == v

    class node:
        """ノードをあらわすクラス
        v: 値
        p: ピボット値
        で初期化
        """
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None class BalancingTree:
    """平衡二分木のクラス
    Pivotを使った実装.
    0以上2^n - 2以下の整数を扱う
    """
    def __init__(self, n):
        """
        2の指数nで初期化
        """
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    def debug(self):
        """デバッグ用の関数"""
        def debug_info(nd_):
            return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1)

        def debug_node(nd):
            re = []
            if nd.left:
                re += debug_node(nd.left)
            if nd.value: re.append(debug_info(nd))
            if nd.right:
                re += debug_node(nd.right)
            return re
        print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50])

    def append(self, v):
        """
        v を追加（その時点で v はない前提）
        """
        v += 1
        nd = self.root
        while True:
            if v == nd.value:
                # v がすでに存在する場合に何か処理が必要ならここに書く
                return 0
            else:
                mi, ma = min(v, nd.value), max(v, nd.value)
                if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

    def leftmost(self, nd):
        if nd.left: return self.leftmost(nd.left)
        return nd

    def rightmost(self, nd):
        if nd.right: return self.rightmost(nd.right)
        return nd

    def find_l(self, v):
        """
        vより真に小さいやつの中での最大値（なければ-1）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value < v: prev = nd.value
        while True:
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                prev = nd.value
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    def find_r(self, v):
        """
        vより真に大きいやつの中での最小値（なければRoot）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value > v: prev = nd.value
        while True:
            if v < nd.value:
                prev = nd.value
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    @property
    def max(self):
        """最大値の属性"""
        return self.find_l((1<<self.N)-1)

    @property
    def min(self):
        """最小値の属性"""
        return self.find_r(-1)

    def delete(self, v, nd = None, prev = None):
        """
        値がvのノードがあれば削除（なければ何もしない）
        """
        v += 1
        if not nd: nd = self.root
        if not prev: prev = nd
        while v != nd.value:
            prev = nd
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return
        if (not nd.left) and (not nd.right):
            if nd.value < prev.value:
                prev.left = None
            else:
                prev.right = None
        elif not nd.left:
            if nd.value < prev.value:
                prev.left = nd.right
            else:
                prev.right = nd.right
        elif not nd.right:
            if nd.value < prev.value:
                prev.left = nd.left
            else:
                prev.right = nd.left
        else:
            nd.value = self.leftmost(nd.right).value
            self.delete(nd.value - 1, nd.right, nd)

    def __contains__(self, v: int) -> bool:
        return self.find_r(v - 1) == v

    class node:
        """ノードをあらわすクラス
        v: 値
        p: ピボット値
        で初期化
        """
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None BalancingTree S = list(S) list(S) S alphabets = list("abcdefghijklmnopqrstuvwxyz") list("abcdefghijklmnopqrstuvwxyz") alphabets S = input() input() S Q = int(input()) int(input()) Q i = int(i) int(i) i tmp = list(input().split()) list(input().split()) tmp bef = S[i-1] S[i-1] bef l, r = tmp tmp l l = int(l) int(l) l Trees = [BalancingTree(50) for _ in range(26)] [BalancingTree(50) for _ in range(26)] Trees r = int(r) int(r) r c2n = {c: i for i, c in enumerate(alphabets)} {c: i for i, c in enumerate(alphabets)} c2n ans = 0 0 ans res = Trees[char].find_r(l-1) Trees[char].find_r(l-1) res r = tmp tmp r _, l, r = tmp tmp _ N = int(input()) int(input()) N ans += 1 1 ans
class BalancingTree:
    """平衡二分木のクラス
    Pivotを使った実装.
    0以上2^n - 2以下の整数を扱う
    """
    def __init__(self, n):
        """
        2の指数nで初期化
        """
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    def debug(self):
        """デバッグ用の関数"""
        def debug_info(nd_):
            return (nd_.value - 1, nd_.pivot - 1, nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1)

        def debug_node(nd):
            re = []
            if nd.left:
                re += debug_node(nd.left)
            if nd.value: re.append(debug_info(nd))
            if nd.right:
                re += debug_node(nd.right)
            return re
        print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50])

    def append(self, v):
        """
        v を追加（その時点で v はない前提）
        """
        v += 1
        nd = self.root
        while True:
            if v == nd.value:
                # v がすでに存在する場合に何か処理が必要ならここに書く
                return 0
            else:
                mi, ma = min(v, nd.value), max(v, nd.value)
                if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2)
                        break

    def leftmost(self, nd):
        if nd.left: return self.leftmost(nd.left)
        return nd

    def rightmost(self, nd):
        if nd.right: return self.rightmost(nd.right)
        return nd

    def find_l(self, v):
        """
        vより真に小さいやつの中での最大値（なければ-1）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value < v: prev = nd.value
        while True:
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                prev = nd.value
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    def find_r(self, v):
        """
        vより真に大きいやつの中での最小値（なければRoot）
        """
        v += 1
        nd = self.root
        prev = 0
        if nd.value > v: prev = nd.value
        while True:
            if v < nd.value:
                prev = nd.value
                if nd.left:
                    nd = nd.left
                else:
                    return prev - 1
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return prev - 1

    @property
    def max(self):
        """最大値の属性"""
        return self.find_l((1<<self.N)-1)

    @property
    def min(self):
        """最小値の属性"""
        return self.find_r(-1)

    def delete(self, v, nd = None, prev = None):
        """
        値がvのノードがあれば削除（なければ何もしない）
        """
        v += 1
        if not nd: nd = self.root
        if not prev: prev = nd
        while v != nd.value:
            prev = nd
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return
        if (not nd.left) and (not nd.right):
            if nd.value < prev.value:
                prev.left = None
            else:
                prev.right = None
        elif not nd.left:
            if nd.value < prev.value:
                prev.left = nd.right
            else:
                prev.right = nd.right
        elif not nd.right:
            if nd.value < prev.value:
                prev.left = nd.left
            else:
                prev.right = nd.left
        else:
            nd.value = self.leftmost(nd.right).value
            self.delete(nd.value - 1, nd.right, nd)

    def __contains__(self, v: int) -> bool:
        return self.find_r(v - 1) == v

    class node:
        """ノードをあらわすクラス
        v: 値
        p: ピボット値
        で初期化
        """
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None

Trees = [BalancingTree(50) for _ in range(26)]
N = int(input())
S = input()
Q = int(input())
alphabets = list("abcdefghijklmnopqrstuvwxyz")
c2n = {c: i for i, c in enumerate(alphabets)}
for i in range(N):
    Trees[c2n[S[i]]].append(i+1)
S = list(S)
for _ in range(Q):
    tmp = list(input().split())
    if tmp[0] == "1":
        _, i, c = tmp
        i = int(i)
        bef = S[i-1]
        if bef == c:
            continue
        Trees[c2n[bef]].delete(i)
        Trees[c2n[c]].append(i)
        S[i-1] = c
    else:
        _, l, r = tmp
        l = int(l)
        r = int(r)
        ans = 0
        for char in range(26):
            res = Trees[char].find_r(l-1)
            if l <= res <= r:
                ans += 1
        print(ans)