import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1)


def main():
    N = int(readline())
    S = readline().strip()
    Q = int(readline())

    bit = [BIT(N) for _ in range(26)]
    for i, c in enumerate(S):
        bit[ord(c) - ord('a')].add(i)

    S = list(S)
    ans = []

    for _ in range(Q):
        n, a, b = readline().split()
        if n == '1':
            i = int(a) - 1
            if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
        else:
            res = 0
            for i in range(26):
                if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
            ans.append(res)

    print(*ans, sep='\n')

    return


if __name__ == '__main__':
    main() import sys sys read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = 1 << 60 INF 1 << 60 1 60 MOD = 1000000007 MOD 1000000007 class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1) BIT def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

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

     add i += 1 i 1 while i <= self.n:
            self.data[i] += x
            i += i & -i

     i <= self.n i self.n self n self.data[i] += x self.data[i] self.data self data i x i += i & -i i i & -i i -i i self self i i x=1 x 1 def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
     get_sum i += 1 i 1 x = 0 x 0 while i > 0:
            x += self.data[i]
            i -= i & -i
         i > 0 i 0 x += self.data[i] x self.data[i] self.data self data i i -= i & -i i i & -i i -i i return x x self self i i def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1) get_sum_range return self.get_sum(r - 1) - self.get_sum(l - 1) self.get_sum(r - 1) - self.get_sum(l - 1) self.get_sum(r - 1) self.get_sum self get_sum r - 1 r 1 self.get_sum(l - 1) self.get_sum self get_sum l - 1 l 1 self self l l r r def main():
    N = int(readline())
    S = readline().strip()
    Q = int(readline())

    bit = [BIT(N) for _ in range(26)]
    for i, c in enumerate(S):
        bit[ord(c) - ord('a')].add(i)

    S = list(S)
    ans = []

    for _ in range(Q):
        n, a, b = readline().split()
        if n == '1':
            i = int(a) - 1
            if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
        else:
            res = 0
            for i in range(26):
                if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
            ans.append(res)

    print(*ans, sep='\n')

    return main N = int(readline()) N int(readline()) int readline() readline S = readline().strip() S readline().strip() ().strip () readline strip Q = int(readline()) Q int(readline()) int readline() readline BIT(N) for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) BIT(N) BIT N bit = [BIT(N) for _ in range(26)] bit [BIT(N) for _ in range(26)] for i, c in enumerate(S):
        bit[ord(c) - ord('a')].add(i)

     i c enumerate(S) enumerate S bit[ord(c) - ord('a')].add(i) [ord(c) - ord('a')].add [ord(c) - ord('a')] bit ord(c) - ord('a') ord(c) ord c ord('a') ord 'a' add i S = list(S) S list(S) list S ans = [] ans [] for _ in range(Q):
        n, a, b = readline().split()
        if n == '1':
            i = int(a) - 1
            if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
        else:
            res = 0
            for i in range(26):
                if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
            ans.append(res)

     _ range(Q) range Q n, a, b = readline().split() n readline().split() ().split () readline split a b if n == '1':
            i = int(a) - 1
            if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
        else:
            res = 0
            for i in range(26):
                if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
            ans.append(res)

     n == '1' n '1' i = int(a) - 1 i int(a) - 1 int(a) int a 1 if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
         b != S[i] b S[i] S i bit[ord(S[i]) - ord('a')].add(i, -1) [ord(S[i]) - ord('a')].add [ord(S[i]) - ord('a')] bit ord(S[i]) - ord('a') ord(S[i]) ord S[i] S i ord('a') ord 'a' add i -1 bit[ord(b) - ord('a')].add(i, 1) [ord(b) - ord('a')].add [ord(b) - ord('a')] bit ord(b) - ord('a') ord(b) ord b ord('a') ord 'a' add i 1 S[i] = b S[i] S i b res = 0 res 0 for i in range(26):
                if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
             i range(26) range 26 if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
             bit[i].get_sum_range(int(a) - 1, int(b)) [i].get_sum_range [i] bit i get_sum_range int(a) - 1 int(a) int a 1 int(b) int b res += 1 res 1 ans.append(res) ans.append ans append res print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' return if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main MOD = 1000000007 1000000007 MOD readlines = sys.stdin.readlines sys.stdin.readlines readlines class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1) class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1) BIT readline = sys.stdin.readline sys.stdin.readline readline read = sys.stdin.read sys.stdin.read read INF = 1 << 60 1 << 60 INF def main():
    N = int(readline())
    S = readline().strip()
    Q = int(readline())

    bit = [BIT(N) for _ in range(26)]
    for i, c in enumerate(S):
        bit[ord(c) - ord('a')].add(i)

    S = list(S)
    ans = []

    for _ in range(Q):
        n, a, b = readline().split()
        if n == '1':
            i = int(a) - 1
            if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
        else:
            res = 0
            for i in range(26):
                if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
            ans.append(res)

    print(*ans, sep='\n')

    return def main():
    N = int(readline())
    S = readline().strip()
    Q = int(readline())

    bit = [BIT(N) for _ in range(26)]
    for i, c in enumerate(S):
        bit[ord(c) - ord('a')].add(i)

    S = list(S)
    ans = []

    for _ in range(Q):
        n, a, b = readline().split()
        if n == '1':
            i = int(a) - 1
            if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
        else:
            res = 0
            for i in range(26):
                if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
            ans.append(res)

    print(*ans, sep='\n')

    return main
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    def add(self, i, x=1):
        i += 1
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        i += 1
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i & -i
        return x

    # Return sum for [l, r)
    def get_sum_range(self, l, r):
        return self.get_sum(r - 1) - self.get_sum(l - 1)


def main():
    N = int(readline())
    S = readline().strip()
    Q = int(readline())

    bit = [BIT(N) for _ in range(26)]
    for i, c in enumerate(S):
        bit[ord(c) - ord('a')].add(i)

    S = list(S)
    ans = []

    for _ in range(Q):
        n, a, b = readline().split()
        if n == '1':
            i = int(a) - 1
            if b != S[i]:
                bit[ord(S[i]) - ord('a')].add(i, -1)
                bit[ord(b) - ord('a')].add(i, 1)
                S[i] = b
        else:
            res = 0
            for i in range(26):
                if bit[i].get_sum_range(int(a) - 1, int(b)):
                    res += 1
            ans.append(res)

    print(*ans, sep='\n')

    return


if __name__ == '__main__':
    main()
