#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N = ni()
S = ns()
assert len(S) == N
Q = ni()
qs = []
for i in range(Q):
    q = ns().split()
    qs.append(q)


def main():
    orda = ord("a")
    ords = [ord(ch) - orda for ch in S]
    bits = [BIT(N) for _ in range(26)]
    for i, ch in enumerate(ords):
        bits[ch].add(i + 1, +1)  # 1-origin
    for q in qs:
        if q[0] == "1":
            j = int(q[1])  # 1-origin
            nch = ord(q[2]) - orda
            och = ords[j - 1]
            if nch != och:
                ords[j - 1] = nch
                bits[och].add(j, -1)
                bits[nch].add(j, +1)
        else:
            assert q[0] == "2"
            l, r = int(q[1]), int(q[2])  # 1-origin
            n = 0
            for i in range(26):
                b = bits[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
            print(n)


# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

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

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


main() import sys sys sys.setrecursionlimit(10 ** 8) sys.setrecursionlimit sys setrecursionlimit 10 ** 8 10 8 ni = lambda: int(sys.stdin.readline()) ni lambda: int(sys.stdin.readline()) int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline nm = lambda: map(int, sys.stdin.readline().split()) nm lambda: map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split nl = lambda: list(nm()) nl lambda: list(nm()) list(nm()) list nm() nm ns = lambda: sys.stdin.readline().rstrip() ns lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip N = ni() N ni() ni S = ns() S ns() ns assert len(S) == N len(S) == N len(S) len S N Q = ni() Q ni() ni qs = [] qs [] for i in range(Q):
    q = ns().split()
    qs.append(q) i range(Q) range Q q = ns().split() q ns().split() ().split () ns split qs.append(q) qs.append qs append q def main():
    orda = ord("a")
    ords = [ord(ch) - orda for ch in S]
    bits = [BIT(N) for _ in range(26)]
    for i, ch in enumerate(ords):
        bits[ch].add(i + 1, +1)  # 1-origin
    for q in qs:
        if q[0] == "1":
            j = int(q[1])  # 1-origin
            nch = ord(q[2]) - orda
            och = ords[j - 1]
            if nch != och:
                ords[j - 1] = nch
                bits[och].add(j, -1)
                bits[nch].add(j, +1)
        else:
            assert q[0] == "2"
            l, r = int(q[1]), int(q[2])  # 1-origin
            n = 0
            for i in range(26):
                b = bits[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
            print(n)


# Binary Indexed Tree (Fenwick Tree) main orda = ord("a") orda ord("a") ord "a" ord(ch) - orda for ch in S for ch in S ch S for ch in S ord(ch) - orda ord(ch) ord ch orda ords = [ord(ch) - orda for ch in S] ords [ord(ch) - orda for ch in S] BIT(N) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT(N) BIT N bits = [BIT(N) for _ in range(26)] bits [BIT(N) for _ in range(26)] for i, ch in enumerate(ords):
        bits[ch].add(i + 1, +1)  # 1-origin
     i ch enumerate(ords) enumerate ords bits[ch].add(i + 1, +1) [ch].add [ch] bits ch add i + 1 i 1 +1 1 for q in qs:
        if q[0] == "1":
            j = int(q[1])  # 1-origin
            nch = ord(q[2]) - orda
            och = ords[j - 1]
            if nch != och:
                ords[j - 1] = nch
                bits[och].add(j, -1)
                bits[nch].add(j, +1)
        else:
            assert q[0] == "2"
            l, r = int(q[1]), int(q[2])  # 1-origin
            n = 0
            for i in range(26):
                b = bits[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
            print(n)


# Binary Indexed Tree (Fenwick Tree) q qs if q[0] == "1":
            j = int(q[1])  # 1-origin
            nch = ord(q[2]) - orda
            och = ords[j - 1]
            if nch != och:
                ords[j - 1] = nch
                bits[och].add(j, -1)
                bits[nch].add(j, +1)
        else:
            assert q[0] == "2"
            l, r = int(q[1]), int(q[2])  # 1-origin
            n = 0
            for i in range(26):
                b = bits[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
            print(n)


# Binary Indexed Tree (Fenwick Tree) q[0] == "1" q[0] q 0 "1" j = int(q[1]) j int(q[1]) int q[1] q 1 nch = ord(q[2]) - orda nch ord(q[2]) - orda ord(q[2]) ord q[2] q 2 orda och = ords[j - 1] och ords[j - 1] ords j - 1 j 1 if nch != och:
                ords[j - 1] = nch
                bits[och].add(j, -1)
                bits[nch].add(j, +1)
         nch != och nch och ords[j - 1] = nch ords[j - 1] ords j - 1 j 1 nch bits[och].add(j, -1) [och].add [och] bits och add j -1 bits[nch].add(j, +1) [nch].add [nch] bits nch add j +1 1 assert q[0] == "2" q[0] == "2" q[0] q 0 "2" l, r = int(q[1]), int(q[2]) l int(q[1]) int q[1] q 1 r int(q[2]) int q[2] q 2 n = 0 n 0 for i in range(26):
                b = bits[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
             i range(26) range 26 b = bits[i] b bits[i] bits i if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
             b.sum(r) - b.sum(l - 1) > 0 b.sum(r) - b.sum(l - 1) b.sum(r) b.sum b sum r b.sum(l - 1) b.sum b sum l - 1 l 1 0 n += 1 n 1 print(n) print n class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

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

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i BIT def __init__(self, n):
        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):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

     sum s = 0 s 0 while i > 0:
            s += self.tree[i]
            i -= i & -i
         i > 0 i 0 s += self.tree[i] s self.tree[i] self.tree self tree i i -= i & -i i i & -i i -i i return s s 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 main() main def main():
    orda = ord("a")
    ords = [ord(ch) - orda for ch in S]
    bits = [BIT(N) for _ in range(26)]
    for i, ch in enumerate(ords):
        bits[ch].add(i + 1, +1)  # 1-origin
    for q in qs:
        if q[0] == "1":
            j = int(q[1])  # 1-origin
            nch = ord(q[2]) - orda
            och = ords[j - 1]
            if nch != och:
                ords[j - 1] = nch
                bits[och].add(j, -1)
                bits[nch].add(j, +1)
        else:
            assert q[0] == "2"
            l, r = int(q[1]), int(q[2])  # 1-origin
            n = 0
            for i in range(26):
                b = bits[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
            print(n)


# Binary Indexed Tree (Fenwick Tree) def main():
    orda = ord("a")
    ords = [ord(ch) - orda for ch in S]
    bits = [BIT(N) for _ in range(26)]
    for i, ch in enumerate(ords):
        bits[ch].add(i + 1, +1)  # 1-origin
    for q in qs:
        if q[0] == "1":
            j = int(q[1])  # 1-origin
            nch = ord(q[2]) - orda
            och = ords[j - 1]
            if nch != och:
                ords[j - 1] = nch
                bits[och].add(j, -1)
                bits[nch].add(j, +1)
        else:
            assert q[0] == "2"
            l, r = int(q[1]), int(q[2])  # 1-origin
            n = 0
            for i in range(26):
                b = bits[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
            print(n)


# Binary Indexed Tree (Fenwick Tree) main qs = [] [] qs nl = lambda: list(nm()) lambda: list(nm()) nl ni = lambda: int(sys.stdin.readline()) lambda: int(sys.stdin.readline()) ni S = ns() ns() S nm = lambda: map(int, sys.stdin.readline().split()) lambda: map(int, sys.stdin.readline().split()) nm class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

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

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

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

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i BIT Q = ni() ni() Q N = ni() ni() N q = ns().split() ns().split() q ns = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() ns
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N = ni()
S = ns()
assert len(S) == N
Q = ni()
qs = []
for i in range(Q):
    q = ns().split()
    qs.append(q)


def main():
    orda = ord("a")
    ords = [ord(ch) - orda for ch in S]
    bits = [BIT(N) for _ in range(26)]
    for i, ch in enumerate(ords):
        bits[ch].add(i + 1, +1)  # 1-origin
    for q in qs:
        if q[0] == "1":
            j = int(q[1])  # 1-origin
            nch = ord(q[2]) - orda
            och = ords[j - 1]
            if nch != och:
                ords[j - 1] = nch
                bits[och].add(j, -1)
                bits[nch].add(j, +1)
        else:
            assert q[0] == "2"
            l, r = int(q[1]), int(q[2])  # 1-origin
            n = 0
            for i in range(26):
                b = bits[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
            print(n)


# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

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

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


main()
