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

    def add(self, i, x):
        """tree[i]と関連個所にxを加える"""
        tree = self.tree
        N = self.N
        while i <= N:
            tree[i] += x
            i += i & (-i)

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


def main():
    from string import ascii_lowercase
    import sys
    input = sys.stdin.readline

    N = int(input())
    s = input().rstrip()
    Q = int(input())

    conv = {c: i for i, c in enumerate(ascii_lowercase)}
    s = [conv[c] for c in s]

    bs = [BIT(N) for _ in range(26)]
    for i, c in enumerate(s, 1):
        bs[c].add(i, 1)

    ans = []
    for _ in range(Q):
        it = iter(input().split())
        if next(it) == '1':
            # change
            i = int(next(it))  # 1-indexed
            c = conv[next(it)]

            p = s[i - 1]
            bs[p].add(i, -1)

            s[i - 1] = c
            bs[c].add(i, 1)

        else:
            # count
            l, r = map(int, it)
            cnt = 0
            for b in bs:
                cnt += int(b.sum(r) - b.sum(l - 1) > 0)
            ans.append(cnt)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main() class BIT:
    def __init__(self, N):
        self.tree = [0] * (N + 1)  # 1-indexed
        self.N = N

    def add(self, i, x):
        """tree[i]と関連個所にxを加える"""
        tree = self.tree
        N = self.N
        while i <= N:
            tree[i] += x
            i += i & (-i)

    def sum(self, i):
        tree = self.tree
        s = 0
        while i:
            s += tree[i]
            i -= i & (-i)
        return s BIT def __init__(self, N):
        self.tree = [0] * (N + 1)  # 1-indexed
        self.N = N

     __init__ self.tree = [0] * (N + 1) self.tree self tree [0] * (N + 1) [0] 0 N + 1 N 1 self.N = N self.N self N N self self N N def add(self, i, x):
        """tree[i]と関連個所にxを加える"""
        tree = self.tree
        N = self.N
        while i <= N:
            tree[i] += x
            i += i & (-i)

     add """tree[i]と関連個所にxを加える""" tree = self.tree tree self.tree self tree N = self.N N self.N self N while i <= N:
            tree[i] += x
            i += i & (-i)

     i <= N i N tree[i] += x tree[i] tree i x i += i & (-i) i i & (-i) i -i i self self i i x x def sum(self, i):
        tree = self.tree
        s = 0
        while i:
            s += tree[i]
            i -= i & (-i)
        return s sum tree = self.tree tree self.tree self tree s = 0 s 0 while i:
            s += tree[i]
            i -= i & (-i)
         i s += tree[i] s tree[i] tree i i -= i & (-i) i i & (-i) i -i i return s s self self i i def main():
    from string import ascii_lowercase
    import sys
    input = sys.stdin.readline

    N = int(input())
    s = input().rstrip()
    Q = int(input())

    conv = {c: i for i, c in enumerate(ascii_lowercase)}
    s = [conv[c] for c in s]

    bs = [BIT(N) for _ in range(26)]
    for i, c in enumerate(s, 1):
        bs[c].add(i, 1)

    ans = []
    for _ in range(Q):
        it = iter(input().split())
        if next(it) == '1':
            # change
            i = int(next(it))  # 1-indexed
            c = conv[next(it)]

            p = s[i - 1]
            bs[p].add(i, -1)

            s[i - 1] = c
            bs[c].add(i, 1)

        else:
            # count
            l, r = map(int, it)
            cnt = 0
            for b in bs:
                cnt += int(b.sum(r) - b.sum(l - 1) > 0)
            ans.append(cnt)
    print(*ans, sep='\n') main from string import ascii_lowercase import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N = int(input()) N int(input()) int input() input s = input().rstrip() s input().rstrip() ().rstrip () input rstrip Q = int(input()) Q int(input()) int input() input c: i for i, c in enumerate(ascii_lowercase) for i, c in enumerate(ascii_lowercase) i c enumerate(ascii_lowercase) enumerate ascii_lowercase for i, c in enumerate(ascii_lowercase) c i conv = {c: i for i, c in enumerate(ascii_lowercase)} conv {c: i for i, c in enumerate(ascii_lowercase)} conv[c] for c in s for c in s c s for c in s conv[c] conv c s = [conv[c] for c in s] s [conv[c] for c in s] BIT(N) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT(N) BIT N bs = [BIT(N) for _ in range(26)] bs [BIT(N) for _ in range(26)] for i, c in enumerate(s, 1):
        bs[c].add(i, 1)

     i c enumerate(s, 1) enumerate s 1 bs[c].add(i, 1) [c].add [c] bs c add i 1 ans = [] ans [] for _ in range(Q):
        it = iter(input().split())
        if next(it) == '1':
            # change
            i = int(next(it))  # 1-indexed
            c = conv[next(it)]

            p = s[i - 1]
            bs[p].add(i, -1)

            s[i - 1] = c
            bs[c].add(i, 1)

        else:
            # count
            l, r = map(int, it)
            cnt = 0
            for b in bs:
                cnt += int(b.sum(r) - b.sum(l - 1) > 0)
            ans.append(cnt)
     _ range(Q) range Q it = iter(input().split()) it iter(input().split()) iter input().split() ().split () input split if next(it) == '1':
            # change
            i = int(next(it))  # 1-indexed
            c = conv[next(it)]

            p = s[i - 1]
            bs[p].add(i, -1)

            s[i - 1] = c
            bs[c].add(i, 1)

        else:
            # count
            l, r = map(int, it)
            cnt = 0
            for b in bs:
                cnt += int(b.sum(r) - b.sum(l - 1) > 0)
            ans.append(cnt)
     next(it) == '1' next(it) next it '1' i = int(next(it)) i int(next(it)) int next(it) next it c = conv[next(it)] c conv[next(it)] conv next(it) next it p = s[i - 1] p s[i - 1] s i - 1 i 1 bs[p].add(i, -1) [p].add [p] bs p add i -1 s[i - 1] = c s[i - 1] s i - 1 i 1 c bs[c].add(i, 1) [c].add [c] bs c add i 1 l, r = map(int, it) l map(int, it) map int it r cnt = 0 cnt 0 for b in bs:
                cnt += int(b.sum(r) - b.sum(l - 1) > 0)
             b bs cnt += int(b.sum(r) - b.sum(l - 1) > 0) cnt int(b.sum(r) - b.sum(l - 1) > 0) int 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 ans.append(cnt) ans.append ans append cnt print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    from string import ascii_lowercase
    import sys
    input = sys.stdin.readline

    N = int(input())
    s = input().rstrip()
    Q = int(input())

    conv = {c: i for i, c in enumerate(ascii_lowercase)}
    s = [conv[c] for c in s]

    bs = [BIT(N) for _ in range(26)]
    for i, c in enumerate(s, 1):
        bs[c].add(i, 1)

    ans = []
    for _ in range(Q):
        it = iter(input().split())
        if next(it) == '1':
            # change
            i = int(next(it))  # 1-indexed
            c = conv[next(it)]

            p = s[i - 1]
            bs[p].add(i, -1)

            s[i - 1] = c
            bs[c].add(i, 1)

        else:
            # count
            l, r = map(int, it)
            cnt = 0
            for b in bs:
                cnt += int(b.sum(r) - b.sum(l - 1) > 0)
            ans.append(cnt)
    print(*ans, sep='\n') def main():
    from string import ascii_lowercase
    import sys
    input = sys.stdin.readline

    N = int(input())
    s = input().rstrip()
    Q = int(input())

    conv = {c: i for i, c in enumerate(ascii_lowercase)}
    s = [conv[c] for c in s]

    bs = [BIT(N) for _ in range(26)]
    for i, c in enumerate(s, 1):
        bs[c].add(i, 1)

    ans = []
    for _ in range(Q):
        it = iter(input().split())
        if next(it) == '1':
            # change
            i = int(next(it))  # 1-indexed
            c = conv[next(it)]

            p = s[i - 1]
            bs[p].add(i, -1)

            s[i - 1] = c
            bs[c].add(i, 1)

        else:
            # count
            l, r = map(int, it)
            cnt = 0
            for b in bs:
                cnt += int(b.sum(r) - b.sum(l - 1) > 0)
            ans.append(cnt)
    print(*ans, sep='\n') main class BIT:
    def __init__(self, N):
        self.tree = [0] * (N + 1)  # 1-indexed
        self.N = N

    def add(self, i, x):
        """tree[i]と関連個所にxを加える"""
        tree = self.tree
        N = self.N
        while i <= N:
            tree[i] += x
            i += i & (-i)

    def sum(self, i):
        tree = self.tree
        s = 0
        while i:
            s += tree[i]
            i -= i & (-i)
        return s class BIT:
    def __init__(self, N):
        self.tree = [0] * (N + 1)  # 1-indexed
        self.N = N

    def add(self, i, x):
        """tree[i]と関連個所にxを加える"""
        tree = self.tree
        N = self.N
        while i <= N:
            tree[i] += x
            i += i & (-i)

    def sum(self, i):
        tree = self.tree
        s = 0
        while i:
            s += tree[i]
            i -= i & (-i)
        return s BIT
class BIT:
    def __init__(self, N):
        self.tree = [0] * (N + 1)  # 1-indexed
        self.N = N

    def add(self, i, x):
        """tree[i]と関連個所にxを加える"""
        tree = self.tree
        N = self.N
        while i <= N:
            tree[i] += x
            i += i & (-i)

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


def main():
    from string import ascii_lowercase
    import sys
    input = sys.stdin.readline

    N = int(input())
    s = input().rstrip()
    Q = int(input())

    conv = {c: i for i, c in enumerate(ascii_lowercase)}
    s = [conv[c] for c in s]

    bs = [BIT(N) for _ in range(26)]
    for i, c in enumerate(s, 1):
        bs[c].add(i, 1)

    ans = []
    for _ in range(Q):
        it = iter(input().split())
        if next(it) == '1':
            # change
            i = int(next(it))  # 1-indexed
            c = conv[next(it)]

            p = s[i - 1]
            bs[p].add(i, -1)

            s[i - 1] = c
            bs[c].add(i, 1)

        else:
            # count
            l, r = map(int, it)
            cnt = 0
            for b in bs:
                cnt += int(b.sum(r) - b.sum(l - 1) > 0)
            ans.append(cnt)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()
