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 RangeUpdate:
    def __init__(self, n):
        self.p = BIT(n + 1)
        self.q = BIT(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) - self.q.sum(s) * s


def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = [dic[s] for s in input().rstrip()]
    Q = int(input())
    Query = [[i for i in input().split()] for _ in [0]*Q]
    BIT26 = [RangeUpdate(N) for _ in [0]*26]
    for i, j in enumerate(S, start=1):
        BIT26[j].add(i, i, 1)
    answer = []
    for A in Query:
        if A[0] == "1":
            i = int(A[1])
            j = S[i-1]
            BIT26[j].add(i, i, -1)
            j = dic[A[2]]
            S[i-1] = j
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            cur = 0
            for i in range(26):
                v = BIT26[i].sum(le, ri)
                if 0 < v:
                    ans += 1
                cur += v
                if ri - le + 1 == v:
                    break
            answer.append(ans)
    print(*answer, sep="\n")


if __name__ == '__main__':
    main() 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 class RangeUpdate:
    def __init__(self, n):
        self.p = BIT(n + 1)
        self.q = BIT(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) - self.q.sum(s) * s RangeUpdate def __init__(self, n):
        self.p = BIT(n + 1)
        self.q = BIT(n + 1)

     __init__ self.p = BIT(n + 1) self.p self p BIT(n + 1) BIT n + 1 n 1 self.q = BIT(n + 1) self.q self q BIT(n + 1) BIT n + 1 n 1 self self n n def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

     add t += 1 t 1 self.p.add(s, -x * s) self.p.add self.p self p add s -x * s -x x s self.p.add(t, x * t) self.p.add self.p self p add t x * t x t self.q.add(s, x) self.q.add self.q self q add s x self.q.add(t, -x) self.q.add self.q self q add t -x x self self s s t t x x def sum(self, s, t):
        t += 1
        return self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) - self.q.sum(s) * s sum t += 1 t 1 return self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) - self.q.sum(s) * s self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) - self.q.sum(s) * s self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) self.p.sum(t) + self.q.sum(t) * t self.p.sum(t) self.p.sum self.p self p sum t self.q.sum(t) * t self.q.sum(t) self.q.sum self.q self q sum t t self.p.sum(s) self.p.sum self.p self p sum s self.q.sum(s) * s self.q.sum(s) self.q.sum self.q self q sum s s self self s s t t def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = [dic[s] for s in input().rstrip()]
    Q = int(input())
    Query = [[i for i in input().split()] for _ in [0]*Q]
    BIT26 = [RangeUpdate(N) for _ in [0]*26]
    for i, j in enumerate(S, start=1):
        BIT26[j].add(i, i, 1)
    answer = []
    for A in Query:
        if A[0] == "1":
            i = int(A[1])
            j = S[i-1]
            BIT26[j].add(i, i, -1)
            j = dic[A[2]]
            S[i-1] = j
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            cur = 0
            for i in range(26):
                v = BIT26[i].sum(le, ri)
                if 0 < v:
                    ans += 1
                cur += v
                if ri - le + 1 == v:
                    break
            answer.append(ans)
    print(*answer, sep="\n") main from string import ascii_lowercase s: i for i, s in enumerate(ascii_lowercase) for i, s in enumerate(ascii_lowercase) i s enumerate(ascii_lowercase) enumerate ascii_lowercase for i, s in enumerate(ascii_lowercase) s i dic = {s: i for i, s in enumerate(ascii_lowercase)} dic {s: i for i, s in enumerate(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 dic[s] for s in input().rstrip() for s in input().rstrip() s input().rstrip() ().rstrip () input rstrip for s in input().rstrip() dic[s] dic s S = [dic[s] for s in input().rstrip()] S [dic[s] for s in input().rstrip()] Q = int(input()) Q int(input()) int input() input [i for i in input().split()] for _ in [0]*Q for _ in [0]*Q _ [0]*Q [0] 0 Q for _ in [0]*Q [i for i in input().split()] Query = [[i for i in input().split()] for _ in [0]*Q] Query [[i for i in input().split()] for _ in [0]*Q] RangeUpdate(N) for _ in [0]*26 for _ in [0]*26 _ [0]*26 [0] 0 26 for _ in [0]*26 RangeUpdate(N) RangeUpdate N BIT26 = [RangeUpdate(N) for _ in [0]*26] BIT26 [RangeUpdate(N) for _ in [0]*26] for i, j in enumerate(S, start=1):
        BIT26[j].add(i, i, 1)
     i j enumerate(S, start=1) enumerate S start=1 start 1 BIT26[j].add(i, i, 1) [j].add [j] BIT26 j add i i 1 answer = [] answer [] for A in Query:
        if A[0] == "1":
            i = int(A[1])
            j = S[i-1]
            BIT26[j].add(i, i, -1)
            j = dic[A[2]]
            S[i-1] = j
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            cur = 0
            for i in range(26):
                v = BIT26[i].sum(le, ri)
                if 0 < v:
                    ans += 1
                cur += v
                if ri - le + 1 == v:
                    break
            answer.append(ans)
     A Query if A[0] == "1":
            i = int(A[1])
            j = S[i-1]
            BIT26[j].add(i, i, -1)
            j = dic[A[2]]
            S[i-1] = j
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            cur = 0
            for i in range(26):
                v = BIT26[i].sum(le, ri)
                if 0 < v:
                    ans += 1
                cur += v
                if ri - le + 1 == v:
                    break
            answer.append(ans)
     A[0] == "1" A[0] A 0 "1" i = int(A[1]) i int(A[1]) int A[1] A 1 j = S[i-1] j S[i-1] S i-1 i 1 BIT26[j].add(i, i, -1) [j].add [j] BIT26 j add i i -1 j = dic[A[2]] j dic[A[2]] dic A[2] A 2 S[i-1] = j S[i-1] S i-1 i 1 j BIT26[j].add(i, i, 1) [j].add [j] BIT26 j add i i 1 le = int(A[1]) le int(A[1]) int A[1] A 1 ri = int(A[2]) ri int(A[2]) int A[2] A 2 ans = 0 ans 0 cur = 0 cur 0 for i in range(26):
                v = BIT26[i].sum(le, ri)
                if 0 < v:
                    ans += 1
                cur += v
                if ri - le + 1 == v:
                    break
             i range(26) range 26 v = BIT26[i].sum(le, ri) v BIT26[i].sum(le, ri) [i].sum [i] BIT26 i sum le ri if 0 < v:
                    ans += 1
                 0 < v 0 v ans += 1 ans 1 cur += v cur v if ri - le + 1 == v:
                    break
             ri - le + 1 == v ri - le + 1 ri - le ri le 1 v break answer.append(ans) answer.append answer append ans print(*answer, sep="\n") print *answer answer sep="\n" sep "\n" if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = [dic[s] for s in input().rstrip()]
    Q = int(input())
    Query = [[i for i in input().split()] for _ in [0]*Q]
    BIT26 = [RangeUpdate(N) for _ in [0]*26]
    for i, j in enumerate(S, start=1):
        BIT26[j].add(i, i, 1)
    answer = []
    for A in Query:
        if A[0] == "1":
            i = int(A[1])
            j = S[i-1]
            BIT26[j].add(i, i, -1)
            j = dic[A[2]]
            S[i-1] = j
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            cur = 0
            for i in range(26):
                v = BIT26[i].sum(le, ri)
                if 0 < v:
                    ans += 1
                cur += v
                if ri - le + 1 == v:
                    break
            answer.append(ans)
    print(*answer, sep="\n") def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = [dic[s] for s in input().rstrip()]
    Q = int(input())
    Query = [[i for i in input().split()] for _ in [0]*Q]
    BIT26 = [RangeUpdate(N) for _ in [0]*26]
    for i, j in enumerate(S, start=1):
        BIT26[j].add(i, i, 1)
    answer = []
    for A in Query:
        if A[0] == "1":
            i = int(A[1])
            j = S[i-1]
            BIT26[j].add(i, i, -1)
            j = dic[A[2]]
            S[i-1] = j
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            cur = 0
            for i in range(26):
                v = BIT26[i].sum(le, ri)
                if 0 < v:
                    ans += 1
                cur += v
                if ri - le + 1 == v:
                    break
            answer.append(ans)
    print(*answer, sep="\n") main class RangeUpdate:
    def __init__(self, n):
        self.p = BIT(n + 1)
        self.q = BIT(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) - self.q.sum(s) * s class RangeUpdate:
    def __init__(self, n):
        self.p = BIT(n + 1)
        self.q = BIT(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) - self.q.sum(s) * s RangeUpdate 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
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 RangeUpdate:
    def __init__(self, n):
        self.p = BIT(n + 1)
        self.q = BIT(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) - self.q.sum(s) * s


def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = [dic[s] for s in input().rstrip()]
    Q = int(input())
    Query = [[i for i in input().split()] for _ in [0]*Q]
    BIT26 = [RangeUpdate(N) for _ in [0]*26]
    for i, j in enumerate(S, start=1):
        BIT26[j].add(i, i, 1)
    answer = []
    for A in Query:
        if A[0] == "1":
            i = int(A[1])
            j = S[i-1]
            BIT26[j].add(i, i, -1)
            j = dic[A[2]]
            S[i-1] = j
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            cur = 0
            for i in range(26):
                v = BIT26[i].sum(le, ri)
                if 0 < v:
                    ans += 1
                cur += v
                if ri - le + 1 == v:
                    break
            answer.append(ans)
    print(*answer, sep="\n")


if __name__ == '__main__':
    main()
