class BalancingTree:
    def __init__(self, n):
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    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: v = 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
        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:
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None

k = (500000+1).bit_length()
dic = {}
for i in range(97, 123):
    dic[chr(i)] = BalancingTree(k)

n = int(input())
s = input()
lst = []
for i in range(n):
    lst.append(s[i])
    dic[s[i]].append(i)

ans = []
q = int(input())
for _ in range(q):
    que = input()
    if que[0] == '1':
        kind, i, c = que.split()
        i = int(i) - 1
        dic[lst[i]].delete(i)
        dic[c].append(i)
        lst[i] = c
    else:
        kind, l, r = map(int, que.split())
        l -= 2; r -= 1
        temp = 0
        for key in dic.keys():
            if dic[key].find_r(l) <= r:
                temp += 1
        ans.append(temp)

for i in ans:
    print(i) class BalancingTree:
    def __init__(self, n):
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    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: v = 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
        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:
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None BalancingTree def __init__(self, n):
        self.N = n
        self.root = self.node(1<<n, 1<<n)

     __init__ 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 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 += 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: v = 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 nd = self.root nd self.root self root prev = 0 prev 0 if nd.value < v: v = 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
        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 += 1 v 1 nd = self.root nd self.root self root prev = 0 prev 0 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 += 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:
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None node 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 k = (500000+1).bit_length() k (500000+1).bit_length() 500000+1).bit_length 500000+1 500000 1 bit_length dic = {} dic {} for i in range(97, 123):
    dic[chr(i)] = BalancingTree(k) i range(97, 123) range 97 123 dic[chr(i)] = BalancingTree(k) dic[chr(i)] dic chr(i) chr i BalancingTree(k) BalancingTree k n = int(input()) n int(input()) int input() input s = input() s input() input lst = [] lst [] for i in range(n):
    lst.append(s[i])
    dic[s[i]].append(i) i range(n) range n lst.append(s[i]) lst.append lst append s[i] s i dic[s[i]].append(i) [s[i]].append [s[i]] dic s[i] s i append i ans = [] ans [] q = int(input()) q int(input()) int input() input for _ in range(q):
    que = input()
    if que[0] == '1':
        kind, i, c = que.split()
        i = int(i) - 1
        dic[lst[i]].delete(i)
        dic[c].append(i)
        lst[i] = c
    else:
        kind, l, r = map(int, que.split())
        l -= 2; r -= 1
        temp = 0
        for key in dic.keys():
            if dic[key].find_r(l) <= r:
                temp += 1
        ans.append(temp) _ range(q) range q que = input() que input() input if que[0] == '1':
        kind, i, c = que.split()
        i = int(i) - 1
        dic[lst[i]].delete(i)
        dic[c].append(i)
        lst[i] = c
    else:
        kind, l, r = map(int, que.split())
        l -= 2; r -= 1
        temp = 0
        for key in dic.keys():
            if dic[key].find_r(l) <= r:
                temp += 1
        ans.append(temp) que[0] == '1' que[0] que 0 '1' kind, i, c = que.split() kind que.split() que.split que split i c i = int(i) - 1 i int(i) - 1 int(i) int i 1 dic[lst[i]].delete(i) [lst[i]].delete [lst[i]] dic lst[i] lst i delete i dic[c].append(i) [c].append [c] dic c append i lst[i] = c lst[i] lst i c kind, l, r = map(int, que.split()) kind map(int, que.split()) map int que.split() que.split que split l r l -= 2 l 2 r -= 1 r 1 temp = 0 temp 0 for key in dic.keys():
            if dic[key].find_r(l) <= r:
                temp += 1
         key dic.keys() dic.keys dic keys if dic[key].find_r(l) <= r:
                temp += 1
         dic[key].find_r(l) <= r dic[key].find_r(l) [key].find_r [key] dic key find_r l r temp += 1 temp 1 ans.append(temp) ans.append ans append temp for i in ans:
    print(i) i ans print(i) print i c = que.split() que.split() c i, c = que.split() que.split() i l -= 2 2 l lst = [] [] lst q = int(input()) int(input()) q class BalancingTree:
    def __init__(self, n):
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    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: v = 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
        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:
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None class BalancingTree:
    def __init__(self, n):
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    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: v = 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
        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:
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None BalancingTree temp = 0 0 temp que = input() input() que s = input() input() s n = int(input()) int(input()) n temp += 1 1 temp dic = {} {} dic i = int(i) - 1 int(i) - 1 i ans = [] [] ans kind, l, r = map(int, que.split()) map(int, que.split()) kind kind, i, c = que.split() que.split() kind r = map(int, que.split()) map(int, que.split()) r r -= 1 1 r l, r = map(int, que.split()) map(int, que.split()) l k = (500000+1).bit_length() (500000+1).bit_length() k
class BalancingTree:
    def __init__(self, n):
        self.N = n
        self.root = self.node(1<<n, 1<<n)

    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: v = 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
        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:
        def __init__(self, v, p):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None

k = (500000+1).bit_length()
dic = {}
for i in range(97, 123):
    dic[chr(i)] = BalancingTree(k)

n = int(input())
s = input()
lst = []
for i in range(n):
    lst.append(s[i])
    dic[s[i]].append(i)

ans = []
q = int(input())
for _ in range(q):
    que = input()
    if que[0] == '1':
        kind, i, c = que.split()
        i = int(i) - 1
        dic[lst[i]].delete(i)
        dic[c].append(i)
        lst[i] = c
    else:
        kind, l, r = map(int, que.split())
        l -= 2; r -= 1
        temp = 0
        for key in dic.keys():
            if dic[key].find_r(l) <= r:
                temp += 1
        ans.append(temp)

for i in ans:
    print(i)