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)}
    N = int(input())
    S = [s for s in input()]
    BIT26 = [RangeUpdate(N) for i in range(26)]
    for i, s in enumerate(S):
        j = dic[s]
        BIT26[j].add(i+1, i+1, 1)
    Q = int(input())
    for query in range(Q):
        A = [i for i in input().split()]
        if A[0] == "1":
            i = int(A[1])
            c = A[2]
            pre = S[i-1]
            j = dic[pre]
            BIT26[j].add(i, i, -1)
            S[i-1] = c
            j = dic[c]
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            for i in range(26):
                if 0 < BIT26[i].sum(le, ri):
                    ans += 1
            print(ans)


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)}
    N = int(input())
    S = [s for s in input()]
    BIT26 = [RangeUpdate(N) for i in range(26)]
    for i, s in enumerate(S):
        j = dic[s]
        BIT26[j].add(i+1, i+1, 1)
    Q = int(input())
    for query in range(Q):
        A = [i for i in input().split()]
        if A[0] == "1":
            i = int(A[1])
            c = A[2]
            pre = S[i-1]
            j = dic[pre]
            BIT26[j].add(i, i, -1)
            S[i-1] = c
            j = dic[c]
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            for i in range(26):
                if 0 < BIT26[i].sum(le, ri):
                    ans += 1
            print(ans) 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)} N = int(input()) N int(input()) int input() input s for s in input() for s in input() s input() input for s in input() s S = [s for s in input()] S [s for s in input()] RangeUpdate(N) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) RangeUpdate(N) RangeUpdate N BIT26 = [RangeUpdate(N) for i in range(26)] BIT26 [RangeUpdate(N) for i in range(26)] for i, s in enumerate(S):
        j = dic[s]
        BIT26[j].add(i+1, i+1, 1)
     i s enumerate(S) enumerate S j = dic[s] j dic[s] dic s BIT26[j].add(i+1, i+1, 1) [j].add [j] BIT26 j add i+1 i 1 i+1 i 1 1 Q = int(input()) Q int(input()) int input() input for query in range(Q):
        A = [i for i in input().split()]
        if A[0] == "1":
            i = int(A[1])
            c = A[2]
            pre = S[i-1]
            j = dic[pre]
            BIT26[j].add(i, i, -1)
            S[i-1] = c
            j = dic[c]
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            for i in range(26):
                if 0 < BIT26[i].sum(le, ri):
                    ans += 1
            print(ans) query range(Q) range Q i for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() i A = [i for i in input().split()] A [i for i in input().split()] if A[0] == "1":
            i = int(A[1])
            c = A[2]
            pre = S[i-1]
            j = dic[pre]
            BIT26[j].add(i, i, -1)
            S[i-1] = c
            j = dic[c]
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            for i in range(26):
                if 0 < BIT26[i].sum(le, ri):
                    ans += 1
            print(ans) A[0] == "1" A[0] A 0 "1" i = int(A[1]) i int(A[1]) int A[1] A 1 c = A[2] c A[2] A 2 pre = S[i-1] pre S[i-1] S i-1 i 1 j = dic[pre] j dic[pre] dic pre BIT26[j].add(i, i, -1) [j].add [j] BIT26 j add i i -1 S[i-1] = c S[i-1] S i-1 i 1 c j = dic[c] j dic[c] dic c 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 for i in range(26):
                if 0 < BIT26[i].sum(le, ri):
                    ans += 1
             i range(26) range 26 if 0 < BIT26[i].sum(le, ri):
                    ans += 1
             0 < BIT26[i].sum(le, ri) 0 BIT26[i].sum(le, ri) [i].sum [i] BIT26 i sum le ri ans += 1 ans 1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' 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 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 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 def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    S = [s for s in input()]
    BIT26 = [RangeUpdate(N) for i in range(26)]
    for i, s in enumerate(S):
        j = dic[s]
        BIT26[j].add(i+1, i+1, 1)
    Q = int(input())
    for query in range(Q):
        A = [i for i in input().split()]
        if A[0] == "1":
            i = int(A[1])
            c = A[2]
            pre = S[i-1]
            j = dic[pre]
            BIT26[j].add(i, i, -1)
            S[i-1] = c
            j = dic[c]
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            for i in range(26):
                if 0 < BIT26[i].sum(le, ri):
                    ans += 1
            print(ans) def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    N = int(input())
    S = [s for s in input()]
    BIT26 = [RangeUpdate(N) for i in range(26)]
    for i, s in enumerate(S):
        j = dic[s]
        BIT26[j].add(i+1, i+1, 1)
    Q = int(input())
    for query in range(Q):
        A = [i for i in input().split()]
        if A[0] == "1":
            i = int(A[1])
            c = A[2]
            pre = S[i-1]
            j = dic[pre]
            BIT26[j].add(i, i, -1)
            S[i-1] = c
            j = dic[c]
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            for i in range(26):
                if 0 < BIT26[i].sum(le, ri):
                    ans += 1
            print(ans) 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


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)}
    N = int(input())
    S = [s for s in input()]
    BIT26 = [RangeUpdate(N) for i in range(26)]
    for i, s in enumerate(S):
        j = dic[s]
        BIT26[j].add(i+1, i+1, 1)
    Q = int(input())
    for query in range(Q):
        A = [i for i in input().split()]
        if A[0] == "1":
            i = int(A[1])
            c = A[2]
            pre = S[i-1]
            j = dic[pre]
            BIT26[j].add(i, i, -1)
            S[i-1] = c
            j = dic[c]
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            for i in range(26):
                if 0 < BIT26[i].sum(le, ri):
                    ans += 1
            print(ans)


if __name__ == '__main__':
    main()
