import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


class BIT:
    def __init__(self, L):
        self.n = len(L)
        self.bit = [0] * (self.n + 1)

    def update(self, idx, x):
        while idx <= self.n:
            self.bit[idx] += x
            idx += idx & (-idx)

    def query(self, idx):
        res = 0
        while idx > 0:
            res += self.bit[idx]
            idx -= idx & (-idx)
        return res

    def sec_sum(self, left, right):
        return self.query(right) - self.query(left - 1)

    def debug(self):
        print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)])


def resolve():
    n = int(input())
    S = list(input().rstrip())
    q = int(input())

    bits = [BIT(S) for _ in range(26)]
    for idx in range(1, n + 1):
        s = S[idx - 1]
        bits[ord(s) - ord("a")].update(idx, 1)

    for _ in range(q):
        query = list(input().split())
        if query[0] == "1":
            i, c = int(query[1]), query[2]
            prev = S[i - 1]
            bits[ord(prev) - ord("a")].update(i, -1)
            bits[ord(c) - ord("a")].update(i, 1)
            S[i - 1] = c
        else:
            l, r = int(query[1]), int(query[2])
            res = 0
            for j in range(26):
                if bits[j].sec_sum(l, r):
                    res += 1
            print(res)


if __name__ == '__main__':
    resolve() import sys sys sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 f_inf = float('inf') f_inf float('inf') float 'inf' mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 class BIT:
    def __init__(self, L):
        self.n = len(L)
        self.bit = [0] * (self.n + 1)

    def update(self, idx, x):
        while idx <= self.n:
            self.bit[idx] += x
            idx += idx & (-idx)

    def query(self, idx):
        res = 0
        while idx > 0:
            res += self.bit[idx]
            idx -= idx & (-idx)
        return res

    def sec_sum(self, left, right):
        return self.query(right) - self.query(left - 1)

    def debug(self):
        print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)]) BIT def __init__(self, L):
        self.n = len(L)
        self.bit = [0] * (self.n + 1)

     __init__ self.n = len(L) self.n self n len(L) len L self.bit = [0] * (self.n + 1) self.bit self bit [0] * (self.n + 1) [0] 0 self.n + 1 self.n self n 1 self self L L def update(self, idx, x):
        while idx <= self.n:
            self.bit[idx] += x
            idx += idx & (-idx)

     update while idx <= self.n:
            self.bit[idx] += x
            idx += idx & (-idx)

     idx <= self.n idx self.n self n self.bit[idx] += x self.bit[idx] self.bit self bit idx x idx += idx & (-idx) idx idx & (-idx) idx -idx idx self self idx idx x x def query(self, idx):
        res = 0
        while idx > 0:
            res += self.bit[idx]
            idx -= idx & (-idx)
        return res

     query res = 0 res 0 while idx > 0:
            res += self.bit[idx]
            idx -= idx & (-idx)
         idx > 0 idx 0 res += self.bit[idx] res self.bit[idx] self.bit self bit idx idx -= idx & (-idx) idx idx & (-idx) idx -idx idx return res res self self idx idx def sec_sum(self, left, right):
        return self.query(right) - self.query(left - 1)

     sec_sum return self.query(right) - self.query(left - 1) self.query(right) - self.query(left - 1) self.query(right) self.query self query right self.query(left - 1) self.query self query left - 1 left 1 self self left left right right def debug(self):
        print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)]) debug self.sec_sum(i, i) for i in range(1, self.n + 1) for i in range(1, self.n + 1) i range(1, self.n + 1) range 1 self.n + 1 self.n self n 1 for i in range(1, self.n + 1) self.sec_sum(i, i) self.sec_sum self sec_sum i i print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)]) print *[self.sec_sum(i, i) for i in range(1, self.n + 1)] [self.sec_sum(i, i) for i in range(1, self.n + 1)] self self def resolve():
    n = int(input())
    S = list(input().rstrip())
    q = int(input())

    bits = [BIT(S) for _ in range(26)]
    for idx in range(1, n + 1):
        s = S[idx - 1]
        bits[ord(s) - ord("a")].update(idx, 1)

    for _ in range(q):
        query = list(input().split())
        if query[0] == "1":
            i, c = int(query[1]), query[2]
            prev = S[i - 1]
            bits[ord(prev) - ord("a")].update(i, -1)
            bits[ord(c) - ord("a")].update(i, 1)
            S[i - 1] = c
        else:
            l, r = int(query[1]), int(query[2])
            res = 0
            for j in range(26):
                if bits[j].sec_sum(l, r):
                    res += 1
            print(res) resolve n = int(input()) n int(input()) int input() input S = list(input().rstrip()) S list(input().rstrip()) list input().rstrip() ().rstrip () input rstrip q = int(input()) q int(input()) int input() input BIT(S) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT(S) BIT S bits = [BIT(S) for _ in range(26)] bits [BIT(S) for _ in range(26)] for idx in range(1, n + 1):
        s = S[idx - 1]
        bits[ord(s) - ord("a")].update(idx, 1)

     idx range(1, n + 1) range 1 n + 1 n 1 s = S[idx - 1] s S[idx - 1] S idx - 1 idx 1 bits[ord(s) - ord("a")].update(idx, 1) [ord(s) - ord("a")].update [ord(s) - ord("a")] bits ord(s) - ord("a") ord(s) ord s ord("a") ord "a" update idx 1 for _ in range(q):
        query = list(input().split())
        if query[0] == "1":
            i, c = int(query[1]), query[2]
            prev = S[i - 1]
            bits[ord(prev) - ord("a")].update(i, -1)
            bits[ord(c) - ord("a")].update(i, 1)
            S[i - 1] = c
        else:
            l, r = int(query[1]), int(query[2])
            res = 0
            for j in range(26):
                if bits[j].sec_sum(l, r):
                    res += 1
            print(res) _ range(q) range q query = list(input().split()) query list(input().split()) list input().split() ().split () input split if query[0] == "1":
            i, c = int(query[1]), query[2]
            prev = S[i - 1]
            bits[ord(prev) - ord("a")].update(i, -1)
            bits[ord(c) - ord("a")].update(i, 1)
            S[i - 1] = c
        else:
            l, r = int(query[1]), int(query[2])
            res = 0
            for j in range(26):
                if bits[j].sec_sum(l, r):
                    res += 1
            print(res) query[0] == "1" query[0] query 0 "1" i, c = int(query[1]), query[2] i int(query[1]) int query[1] query 1 c query[2] query 2 prev = S[i - 1] prev S[i - 1] S i - 1 i 1 bits[ord(prev) - ord("a")].update(i, -1) [ord(prev) - ord("a")].update [ord(prev) - ord("a")] bits ord(prev) - ord("a") ord(prev) ord prev ord("a") ord "a" update i -1 bits[ord(c) - ord("a")].update(i, 1) [ord(c) - ord("a")].update [ord(c) - ord("a")] bits ord(c) - ord("a") ord(c) ord c ord("a") ord "a" update i 1 S[i - 1] = c S[i - 1] S i - 1 i 1 c l, r = int(query[1]), int(query[2]) l int(query[1]) int query[1] query 1 r int(query[2]) int query[2] query 2 res = 0 res 0 for j in range(26):
                if bits[j].sec_sum(l, r):
                    res += 1
             j range(26) range 26 if bits[j].sec_sum(l, r):
                    res += 1
             bits[j].sec_sum(l, r) [j].sec_sum [j] bits j sec_sum l r res += 1 res 1 print(res) print res if __name__ == '__main__':
    resolve() __name__ == '__main__' __name__ '__main__' resolve() resolve class BIT:
    def __init__(self, L):
        self.n = len(L)
        self.bit = [0] * (self.n + 1)

    def update(self, idx, x):
        while idx <= self.n:
            self.bit[idx] += x
            idx += idx & (-idx)

    def query(self, idx):
        res = 0
        while idx > 0:
            res += self.bit[idx]
            idx -= idx & (-idx)
        return res

    def sec_sum(self, left, right):
        return self.query(right) - self.query(left - 1)

    def debug(self):
        print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)]) class BIT:
    def __init__(self, L):
        self.n = len(L)
        self.bit = [0] * (self.n + 1)

    def update(self, idx, x):
        while idx <= self.n:
            self.bit[idx] += x
            idx += idx & (-idx)

    def query(self, idx):
        res = 0
        while idx > 0:
            res += self.bit[idx]
            idx -= idx & (-idx)
        return res

    def sec_sum(self, left, right):
        return self.query(right) - self.query(left - 1)

    def debug(self):
        print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)]) BIT f_inf = float('inf') float('inf') f_inf mod = 10 ** 9 + 7 10 ** 9 + 7 mod def resolve():
    n = int(input())
    S = list(input().rstrip())
    q = int(input())

    bits = [BIT(S) for _ in range(26)]
    for idx in range(1, n + 1):
        s = S[idx - 1]
        bits[ord(s) - ord("a")].update(idx, 1)

    for _ in range(q):
        query = list(input().split())
        if query[0] == "1":
            i, c = int(query[1]), query[2]
            prev = S[i - 1]
            bits[ord(prev) - ord("a")].update(i, -1)
            bits[ord(c) - ord("a")].update(i, 1)
            S[i - 1] = c
        else:
            l, r = int(query[1]), int(query[2])
            res = 0
            for j in range(26):
                if bits[j].sec_sum(l, r):
                    res += 1
            print(res) def resolve():
    n = int(input())
    S = list(input().rstrip())
    q = int(input())

    bits = [BIT(S) for _ in range(26)]
    for idx in range(1, n + 1):
        s = S[idx - 1]
        bits[ord(s) - ord("a")].update(idx, 1)

    for _ in range(q):
        query = list(input().split())
        if query[0] == "1":
            i, c = int(query[1]), query[2]
            prev = S[i - 1]
            bits[ord(prev) - ord("a")].update(i, -1)
            bits[ord(c) - ord("a")].update(i, 1)
            S[i - 1] = c
        else:
            l, r = int(query[1]), int(query[2])
            res = 0
            for j in range(26):
                if bits[j].sec_sum(l, r):
                    res += 1
            print(res) resolve
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


class BIT:
    def __init__(self, L):
        self.n = len(L)
        self.bit = [0] * (self.n + 1)

    def update(self, idx, x):
        while idx <= self.n:
            self.bit[idx] += x
            idx += idx & (-idx)

    def query(self, idx):
        res = 0
        while idx > 0:
            res += self.bit[idx]
            idx -= idx & (-idx)
        return res

    def sec_sum(self, left, right):
        return self.query(right) - self.query(left - 1)

    def debug(self):
        print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)])


def resolve():
    n = int(input())
    S = list(input().rstrip())
    q = int(input())

    bits = [BIT(S) for _ in range(26)]
    for idx in range(1, n + 1):
        s = S[idx - 1]
        bits[ord(s) - ord("a")].update(idx, 1)

    for _ in range(q):
        query = list(input().split())
        if query[0] == "1":
            i, c = int(query[1]), query[2]
            prev = S[i - 1]
            bits[ord(prev) - ord("a")].update(i, -1)
            bits[ord(c) - ord("a")].update(i, 1)
            S[i - 1] = c
        else:
            l, r = int(query[1]), int(query[2])
            res = 0
            for j in range(26):
                if bits[j].sec_sum(l, r):
                    res += 1
            print(res)


if __name__ == '__main__':
    resolve()
