class Binary_Indexed_Tree:
    def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1)) - 1
        return s

    def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

    def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

    def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

    def lower_bound(self, x, equal=False):
        """ (a0+a1+...+ai < x となる最大の i, その時の a0+a1+...+ai )
             a0+a1+...+ai <= x としたい場合は equal = True
             二分探索であるため、ai>=0 を満たす必要がある"""
        sum_ = 0
        pos = -1    # 1-indexed の時は pos = 0
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

    def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i + 1)

    def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i + 1)

    def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2))


def str2int(s):
    return ord(s) - ord("a")


n = int(input())
s = [str2int(i) for i in input()]
B = [Binary_Indexed_Tree(n) for i in range(26)]

for i in range(n):
    B[s[i]].add(i, 1)

for _ in range(int(input())):
    t, a, b = input().split()
    if t == "1":
        a = int(a) - 1
        b = str2int(b)
        B[s[a]].add(a, -1)
        B[b].add(a, 1)
        s[a] = b
    else:
        a, b = int(a) - 1, int(b)
        ans = 0
        for v in B:
            ans += v.get(a, b) > 0
        print(ans) class Binary_Indexed_Tree:
    def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1)) - 1
        return s

    def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

    def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

    def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

    def lower_bound(self, x, equal=False):
        """ (a0+a1+...+ai < x となる最大の i, その時の a0+a1+...+ai )
             a0+a1+...+ai <= x としたい場合は equal = True
             二分探索であるため、ai>=0 を満たす必要がある"""
        sum_ = 0
        pos = -1    # 1-indexed の時は pos = 0
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

    def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i + 1)

    def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i + 1)

    def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2)) Binary_Indexed_Tree def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length() - 1

     __init__ """
        :param n: 最大の要素数
        """ self.n = n self.n self n n self.tree = [0] * (n + 1) self.tree self tree [0] * (n + 1) [0] 0 n + 1 n 1 self.depth = n.bit_length() - 1 self.depth self depth n.bit_length() - 1 n.bit_length() n.bit_length n bit_length 1 self self n n def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1)) - 1
        return s

     sum """ 区間[0,i) の総和を求める """ s = 0 s 0 i -= 1 i 1 while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1)) - 1
         i >= 0 i 0 s += self.tree[i] s self.tree[i] self.tree self tree i i = (i & (i + 1)) - 1 i (i & (i + 1)) - 1 i & (i + 1) i i + 1 i 1 1 return s s self self i i def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

     built """ array を初期値とするBITを構築 """ for i, a in enumerate(array):
            self.add(i, a)

     i a enumerate(array) enumerate array self.add(i, a) self.add self add i a self self array array def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

     add """ i 番目の要素に x を足す """ while i < self.n:
            self.tree[i] += x
            i |= i + 1

     i < self.n i self.n self n self.tree[i] += x self.tree[i] self.tree self tree i x i |= i + 1 i i + 1 i 1 self self i i x x def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

     get """ 部分区間和 [i, j) """ if i == 0:
            return self.sum(j)
         i == 0 i 0 return self.sum(j) self.sum(j) self.sum self sum j return self.sum(j) - self.sum(i) self.sum(j) - self.sum(i) self.sum(j) self.sum self sum j self.sum(i) self.sum self sum i self self i i j j def lower_bound(self, x, equal=False):
        """ (a0+a1+...+ai < x となる最大の i, その時の a0+a1+...+ai )
             a0+a1+...+ai <= x としたい場合は equal = True
             二分探索であるため、ai>=0 を満たす必要がある"""
        sum_ = 0
        pos = -1    # 1-indexed の時は pos = 0
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

     lower_bound """ (a0+a1+...+ai < x となる最大の i, その時の a0+a1+...+ai )
             a0+a1+...+ai <= x としたい場合は equal = True
             二分探索であるため、ai>=0 を満たす必要がある""" sum_ = 0 sum_ 0 pos = -1 pos -1 if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
         not equal equal for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
         i range(self.depth, -1, -1) range self.depth self depth -1 -1 k = pos + (1 << i) k pos + (1 << i) pos 1 << i 1 i if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
         k < self.n and sum_ + self.tree[k] < x k < self.n k self.n self n sum_ + self.tree[k] < x sum_ + self.tree[k] sum_ self.tree[k] self.tree self tree k x sum_ += self.tree[k] sum_ self.tree[k] self.tree self tree k pos += 1 << i pos 1 << i 1 i if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
         equal for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
         i range(self.depth, -1, -1) range self.depth self depth -1 -1 k = pos + (1 << i) k pos + (1 << i) pos 1 << i 1 i if k < self.n and sum_ + self.tree[k] <= x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
         k < self.n and sum_ + self.tree[k] <= x k < self.n k self.n self n sum_ + self.tree[k] <= x sum_ + self.tree[k] sum_ self.tree[k] self.tree self tree k x sum_ += self.tree[k] sum_ self.tree[k] self.tree self tree k pos += 1 << i pos 1 << i 1 i return pos, sum_ return pos, sum_ pos sum_ self self x x equal=False equal False def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i + 1)

     __getitem__ """ [a0, a1, a2, ...] """ return self.get(i, i + 1) self.get(i, i + 1) self.get self get i i + 1 i 1 self self i i def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i + 1)

     __iter__ """ [a0, a1, a2, ...] """ for i in range(self.n):
            yield self.get(i, i + 1)

     i range(self.n) range self.n self n yield self.get(i, i + 1) self.get(i, i + 1) self.get self get i i + 1 i 1 self self def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2)) __str__ text1 = " ".join(["element:            "] + list(map(str, self))) text1 " ".join(["element:            "] + list(map(str, self))) " ".join " " join ["element:            "] + list(map(str, self)) ["element:            "] "element:            " list(map(str, self)) list map(str, self) map str self text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1))) text2 " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1))) " ".join " " join ["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)) ["cumsum(1-indexed):  "] "cumsum(1-indexed):  " list(str(self.sum(i)) for i in range(1, self.n + 1)) list str(self.sum(i)) str self.sum(i) self.sum self sum i return "\n".join((text1, text2)) "\n".join((text1, text2)) "\n".join "\n" join (text1, text2) text1 text2 self self def str2int(s):
    return ord(s) - ord("a") str2int return ord(s) - ord("a") ord(s) - ord("a") ord(s) ord s ord("a") ord "a" s s n = int(input()) n int(input()) int input() input str2int(i) for i in input() for i in input() i input() input for i in input() str2int(i) str2int i s = [str2int(i) for i in input()] s [str2int(i) for i in input()] Binary_Indexed_Tree(n) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) Binary_Indexed_Tree(n) Binary_Indexed_Tree n B = [Binary_Indexed_Tree(n) for i in range(26)] B [Binary_Indexed_Tree(n) for i in range(26)] for i in range(n):
    B[s[i]].add(i, 1) i range(n) range n B[s[i]].add(i, 1) [s[i]].add [s[i]] B s[i] s i add i 1 for _ in range(int(input())):
    t, a, b = input().split()
    if t == "1":
        a = int(a) - 1
        b = str2int(b)
        B[s[a]].add(a, -1)
        B[b].add(a, 1)
        s[a] = b
    else:
        a, b = int(a) - 1, int(b)
        ans = 0
        for v in B:
            ans += v.get(a, b) > 0
        print(ans) _ range(int(input())) range int(input()) int input() input t, a, b = input().split() t input().split() ().split () input split a b if t == "1":
        a = int(a) - 1
        b = str2int(b)
        B[s[a]].add(a, -1)
        B[b].add(a, 1)
        s[a] = b
    else:
        a, b = int(a) - 1, int(b)
        ans = 0
        for v in B:
            ans += v.get(a, b) > 0
        print(ans) t == "1" t "1" a = int(a) - 1 a int(a) - 1 int(a) int a 1 b = str2int(b) b str2int(b) str2int b B[s[a]].add(a, -1) [s[a]].add [s[a]] B s[a] s a add a -1 B[b].add(a, 1) [b].add [b] B b add a 1 s[a] = b s[a] s a b a, b = int(a) - 1, int(b) a int(a) - 1 int(a) int a 1 b int(b) int b ans = 0 ans 0 for v in B:
            ans += v.get(a, b) > 0
         v B ans += v.get(a, b) > 0 ans v.get(a, b) > 0 v.get(a, b) v.get v get a b 0 print(ans) print ans B = [Binary_Indexed_Tree(n) for i in range(26)] [Binary_Indexed_Tree(n) for i in range(26)] B b = str2int(b) str2int(b) b a, b = input().split() input().split() a def str2int(s):
    return ord(s) - ord("a") def str2int(s):
    return ord(s) - ord("a") str2int t, a, b = input().split() input().split() t b = input().split() input().split() b a = int(a) - 1 int(a) - 1 a n = int(input()) int(input()) n s = [str2int(i) for i in input()] [str2int(i) for i in input()] s a, b = int(a) - 1, int(b) int(a) - 1 a ans += v.get(a, b) > 0 v.get(a, b) > 0 ans ans = 0 0 ans b = int(a) - 1, int(b) int(b) b class Binary_Indexed_Tree:
    def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1)) - 1
        return s

    def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

    def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

    def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

    def lower_bound(self, x, equal=False):
        """ (a0+a1+...+ai < x となる最大の i, その時の a0+a1+...+ai )
             a0+a1+...+ai <= x としたい場合は equal = True
             二分探索であるため、ai>=0 を満たす必要がある"""
        sum_ = 0
        pos = -1    # 1-indexed の時は pos = 0
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

    def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i + 1)

    def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i + 1)

    def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2)) class Binary_Indexed_Tree:
    def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1)) - 1
        return s

    def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

    def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

    def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

    def lower_bound(self, x, equal=False):
        """ (a0+a1+...+ai < x となる最大の i, その時の a0+a1+...+ai )
             a0+a1+...+ai <= x としたい場合は equal = True
             二分探索であるため、ai>=0 を満たす必要がある"""
        sum_ = 0
        pos = -1    # 1-indexed の時は pos = 0
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

    def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i + 1)

    def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i + 1)

    def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2)) Binary_Indexed_Tree
class Binary_Indexed_Tree:
    def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1)) - 1
        return s

    def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

    def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

    def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

    def lower_bound(self, x, equal=False):
        """ (a0+a1+...+ai < x となる最大の i, その時の a0+a1+...+ai )
             a0+a1+...+ai <= x としたい場合は equal = True
             二分探索であるため、ai>=0 を満たす必要がある"""
        sum_ = 0
        pos = -1    # 1-indexed の時は pos = 0
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

    def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i + 1)

    def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i + 1)

    def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2))


def str2int(s):
    return ord(s) - ord("a")


n = int(input())
s = [str2int(i) for i in input()]
B = [Binary_Indexed_Tree(n) for i in range(26)]

for i in range(n):
    B[s[i]].add(i, 1)

for _ in range(int(input())):
    t, a, b = input().split()
    if t == "1":
        a = int(a) - 1
        b = str2int(b)
        B[s[a]].add(a, -1)
        B[b].add(a, 1)
        s[a] = b
    else:
        a, b = int(a) - 1, int(b)
        ans = 0
        for v in B:
            ans += v.get(a, b) > 0
        print(ans)
