
class BIT:
    def __init__(self, n):
        # 1-indexed
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N = int(input())
S = list(input())
Q = int(input())

trees = [BIT(5 * 10 ** 5 + 2) for _ in range(26)]
for i in range(N):
    trees[ord(S[i]) - ord("a")].add(i + 1, 1)

for _ in range(Q):
    s, *x = input().split()
    if s == "1":
        i = int(x[0])
        c = x[1]
        trees[ord(S[i - 1]) - ord("a")].add(i, -1)
        trees[ord(c) - ord("a")].add(i, 1)
        S[i - 1] = c
    else:
        l, r = map(int, x)
        cnt = 0
        for i in range(26):
            cnt += int(trees[i].sum(r) - trees[i].sum(l - 1) > 0)
        print(cnt) class BIT:
    def __init__(self, n):
        # 1-indexed
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i BIT def __init__(self, n):
        # 1-indexed
        self.size = n
        self.tree = [0] * (n + 1)

     __init__ self.size = n self.size self size n self.tree = [0] * (n + 1) self.tree self tree [0] * (n + 1) [0] 0 n + 1 n 1 self self n n def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

     sum res = 0 res 0 while i > 0:
            res += self.tree[i]
            i -= i & -i
         i > 0 i 0 res += self.tree[i] res self.tree[i] self.tree self tree i i -= i & -i i i & -i i -i i return res res self self i i def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i add while i <= self.size:
            self.tree[i] += x
            i += i & -i i <= self.size i self.size self size self.tree[i] += x self.tree[i] self.tree self tree i x i += i & -i i i & -i i -i i self self i i x x N = int(input()) N int(input()) int input() input S = list(input()) S list(input()) list input() input Q = int(input()) Q int(input()) int input() input BIT(5 * 10 ** 5 + 2) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT(5 * 10 ** 5 + 2) BIT 5 * 10 ** 5 + 2 5 * 10 ** 5 5 10 ** 5 10 5 2 trees = [BIT(5 * 10 ** 5 + 2) for _ in range(26)] trees [BIT(5 * 10 ** 5 + 2) for _ in range(26)] for i in range(N):
    trees[ord(S[i]) - ord("a")].add(i + 1, 1) i range(N) range N trees[ord(S[i]) - ord("a")].add(i + 1, 1) [ord(S[i]) - ord("a")].add [ord(S[i]) - ord("a")] trees ord(S[i]) - ord("a") ord(S[i]) ord S[i] S i ord("a") ord "a" add i + 1 i 1 1 for _ in range(Q):
    s, *x = input().split()
    if s == "1":
        i = int(x[0])
        c = x[1]
        trees[ord(S[i - 1]) - ord("a")].add(i, -1)
        trees[ord(c) - ord("a")].add(i, 1)
        S[i - 1] = c
    else:
        l, r = map(int, x)
        cnt = 0
        for i in range(26):
            cnt += int(trees[i].sum(r) - trees[i].sum(l - 1) > 0)
        print(cnt) _ range(Q) range Q s, *x = input().split() s input().split() ().split () input split *x x if s == "1":
        i = int(x[0])
        c = x[1]
        trees[ord(S[i - 1]) - ord("a")].add(i, -1)
        trees[ord(c) - ord("a")].add(i, 1)
        S[i - 1] = c
    else:
        l, r = map(int, x)
        cnt = 0
        for i in range(26):
            cnt += int(trees[i].sum(r) - trees[i].sum(l - 1) > 0)
        print(cnt) s == "1" s "1" i = int(x[0]) i int(x[0]) int x[0] x 0 c = x[1] c x[1] x 1 trees[ord(S[i - 1]) - ord("a")].add(i, -1) [ord(S[i - 1]) - ord("a")].add [ord(S[i - 1]) - ord("a")] trees ord(S[i - 1]) - ord("a") ord(S[i - 1]) ord S[i - 1] S i - 1 i 1 ord("a") ord "a" add i -1 trees[ord(c) - ord("a")].add(i, 1) [ord(c) - ord("a")].add [ord(c) - ord("a")] trees ord(c) - ord("a") ord(c) ord c ord("a") ord "a" add i 1 S[i - 1] = c S[i - 1] S i - 1 i 1 c l, r = map(int, x) l map(int, x) map int x r cnt = 0 cnt 0 for i in range(26):
            cnt += int(trees[i].sum(r) - trees[i].sum(l - 1) > 0)
         i range(26) range 26 cnt += int(trees[i].sum(r) - trees[i].sum(l - 1) > 0) cnt int(trees[i].sum(r) - trees[i].sum(l - 1) > 0) int trees[i].sum(r) - trees[i].sum(l - 1) > 0 trees[i].sum(r) - trees[i].sum(l - 1) trees[i].sum(r) [i].sum [i] trees i sum r trees[i].sum(l - 1) [i].sum [i] trees i sum l - 1 l 1 0 print(cnt) print cnt cnt = 0 0 cnt s, *x = input().split() input().split() s S = list(input()) list(input()) S cnt += int(trees[i].sum(r) - trees[i].sum(l - 1) > 0) int(trees[i].sum(r) - trees[i].sum(l - 1) > 0) cnt trees = [BIT(5 * 10 ** 5 + 2) for _ in range(26)] [BIT(5 * 10 ** 5 + 2) for _ in range(26)] trees i = int(x[0]) int(x[0]) i class BIT:
    def __init__(self, n):
        # 1-indexed
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i class BIT:
    def __init__(self, n):
        # 1-indexed
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i BIT c = x[1] x[1] c Q = int(input()) int(input()) Q r = map(int, x) map(int, x) r l, r = map(int, x) map(int, x) l N = int(input()) int(input()) N

class BIT:
    def __init__(self, n):
        # 1-indexed
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N = int(input())
S = list(input())
Q = int(input())

trees = [BIT(5 * 10 ** 5 + 2) for _ in range(26)]
for i in range(N):
    trees[ord(S[i]) - ord("a")].add(i + 1, 1)

for _ in range(Q):
    s, *x = input().split()
    if s == "1":
        i = int(x[0])
        c = x[1]
        trees[ord(S[i - 1]) - ord("a")].add(i, -1)
        trees[ord(c) - ord("a")].add(i, 1)
        S[i - 1] = c
    else:
        l, r = map(int, x)
        cnt = 0
        for i in range(26):
            cnt += int(trees[i].sum(r) - trees[i].sum(l - 1) > 0)
        print(cnt)
