import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    s = list(input())
    q = ni()

    alphabet_idx = {}
    for i in range(26):
        alphabet_idx[i] = []

    for i, si in enumerate(s):
        alphabet_idx[ord(si) - ord("a")].append(i)

    for _ in range(q):
        qi, a, b = input().split()
        qi, a = int(qi), int(a)

        if qi == 1:
            a -= 1
            if s[a] == b:
                continue
            del_char = ord(s[a]) - ord("a")
            del_idx = bisect.bisect_left(alphabet_idx[del_char], a)
            del alphabet_idx[del_char][del_idx]

            insert_char = ord(b) - ord("a")
            insert_idx = bisect.bisect_left(alphabet_idx[insert_char], a)
            alphabet_idx[insert_char].insert(insert_idx, a)

            s[a] = b

        if qi == 2:
            b = int(b)
            a -= 1
            b -= 1
            ans = 0

            for i in range(26):
                a_idx = bisect.bisect_left(alphabet_idx[i], a)
                if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

            print(ans)


if __name__ == '__main__':
    main() import sys sys import math math import collections collections import bisect bisect import itertools itertools import fractions fractions import copy copy import decimal decimal import queue queue sys.setrecursionlimit(10000001) sys.setrecursionlimit sys setrecursionlimit 10000001 INF = 10 ** 16 INF 10 ** 16 10 16 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 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 ns = lambda: map(int, sys.stdin.readline().split()) ns 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 na = lambda: list(map(int, sys.stdin.readline().split())) na lambda: list(map(int, sys.stdin.readline().split())) list(map(int, sys.stdin.readline().split())) list 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 def main():
    n = ni()
    s = list(input())
    q = ni()

    alphabet_idx = {}
    for i in range(26):
        alphabet_idx[i] = []

    for i, si in enumerate(s):
        alphabet_idx[ord(si) - ord("a")].append(i)

    for _ in range(q):
        qi, a, b = input().split()
        qi, a = int(qi), int(a)

        if qi == 1:
            a -= 1
            if s[a] == b:
                continue
            del_char = ord(s[a]) - ord("a")
            del_idx = bisect.bisect_left(alphabet_idx[del_char], a)
            del alphabet_idx[del_char][del_idx]

            insert_char = ord(b) - ord("a")
            insert_idx = bisect.bisect_left(alphabet_idx[insert_char], a)
            alphabet_idx[insert_char].insert(insert_idx, a)

            s[a] = b

        if qi == 2:
            b = int(b)
            a -= 1
            b -= 1
            ans = 0

            for i in range(26):
                a_idx = bisect.bisect_left(alphabet_idx[i], a)
                if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

            print(ans) main n = ni() n ni() ni s = list(input()) s list(input()) list input() input q = ni() q ni() ni alphabet_idx = {} alphabet_idx {} for i in range(26):
        alphabet_idx[i] = []

     i range(26) range 26 alphabet_idx[i] = [] alphabet_idx[i] alphabet_idx i [] for i, si in enumerate(s):
        alphabet_idx[ord(si) - ord("a")].append(i)

     i si enumerate(s) enumerate s alphabet_idx[ord(si) - ord("a")].append(i) [ord(si) - ord("a")].append [ord(si) - ord("a")] alphabet_idx ord(si) - ord("a") ord(si) ord si ord("a") ord "a" append i for _ in range(q):
        qi, a, b = input().split()
        qi, a = int(qi), int(a)

        if qi == 1:
            a -= 1
            if s[a] == b:
                continue
            del_char = ord(s[a]) - ord("a")
            del_idx = bisect.bisect_left(alphabet_idx[del_char], a)
            del alphabet_idx[del_char][del_idx]

            insert_char = ord(b) - ord("a")
            insert_idx = bisect.bisect_left(alphabet_idx[insert_char], a)
            alphabet_idx[insert_char].insert(insert_idx, a)

            s[a] = b

        if qi == 2:
            b = int(b)
            a -= 1
            b -= 1
            ans = 0

            for i in range(26):
                a_idx = bisect.bisect_left(alphabet_idx[i], a)
                if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

            print(ans) _ range(q) range q qi, a, b = input().split() qi input().split() ().split () input split a b qi, a = int(qi), int(a) qi int(qi) int qi a int(a) int a if qi == 1:
            a -= 1
            if s[a] == b:
                continue
            del_char = ord(s[a]) - ord("a")
            del_idx = bisect.bisect_left(alphabet_idx[del_char], a)
            del alphabet_idx[del_char][del_idx]

            insert_char = ord(b) - ord("a")
            insert_idx = bisect.bisect_left(alphabet_idx[insert_char], a)
            alphabet_idx[insert_char].insert(insert_idx, a)

            s[a] = b

         qi == 1 qi 1 a -= 1 a 1 if s[a] == b:
                continue
             s[a] == b s[a] s a b continue del_char = ord(s[a]) - ord("a") del_char ord(s[a]) - ord("a") ord(s[a]) ord s[a] s a ord("a") ord "a" del_idx = bisect.bisect_left(alphabet_idx[del_char], a) del_idx bisect.bisect_left(alphabet_idx[del_char], a) bisect.bisect_left bisect bisect_left alphabet_idx[del_char] alphabet_idx del_char a del alphabet_idx[del_char][del_idx] alphabet_idx[del_char][del_idx] [del_char] alphabet_idx del_char del_idx insert_char = ord(b) - ord("a") insert_char ord(b) - ord("a") ord(b) ord b ord("a") ord "a" insert_idx = bisect.bisect_left(alphabet_idx[insert_char], a) insert_idx bisect.bisect_left(alphabet_idx[insert_char], a) bisect.bisect_left bisect bisect_left alphabet_idx[insert_char] alphabet_idx insert_char a alphabet_idx[insert_char].insert(insert_idx, a) [insert_char].insert [insert_char] alphabet_idx insert_char insert insert_idx a s[a] = b s[a] s a b if qi == 2:
            b = int(b)
            a -= 1
            b -= 1
            ans = 0

            for i in range(26):
                a_idx = bisect.bisect_left(alphabet_idx[i], a)
                if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

            print(ans) qi == 2 qi 2 b = int(b) b int(b) int b a -= 1 a 1 b -= 1 b 1 ans = 0 ans 0 for i in range(26):
                a_idx = bisect.bisect_left(alphabet_idx[i], a)
                if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

             i range(26) range 26 a_idx = bisect.bisect_left(alphabet_idx[i], a) a_idx bisect.bisect_left(alphabet_idx[i], a) bisect.bisect_left bisect bisect_left alphabet_idx[i] alphabet_idx i a if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

             a_idx < len(alphabet_idx[i]) a_idx len(alphabet_idx[i]) len alphabet_idx[i] alphabet_idx i if alphabet_idx[i][a_idx] <= b:
                        ans += 1

             alphabet_idx[i][a_idx] <= b alphabet_idx[i][a_idx] [i] alphabet_idx i a_idx b ans += 1 ans 1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main ns = lambda: map(int, sys.stdin.readline().split()) lambda: map(int, sys.stdin.readline().split()) ns INF = 10 ** 16 10 ** 16 INF def main():
    n = ni()
    s = list(input())
    q = ni()

    alphabet_idx = {}
    for i in range(26):
        alphabet_idx[i] = []

    for i, si in enumerate(s):
        alphabet_idx[ord(si) - ord("a")].append(i)

    for _ in range(q):
        qi, a, b = input().split()
        qi, a = int(qi), int(a)

        if qi == 1:
            a -= 1
            if s[a] == b:
                continue
            del_char = ord(s[a]) - ord("a")
            del_idx = bisect.bisect_left(alphabet_idx[del_char], a)
            del alphabet_idx[del_char][del_idx]

            insert_char = ord(b) - ord("a")
            insert_idx = bisect.bisect_left(alphabet_idx[insert_char], a)
            alphabet_idx[insert_char].insert(insert_idx, a)

            s[a] = b

        if qi == 2:
            b = int(b)
            a -= 1
            b -= 1
            ans = 0

            for i in range(26):
                a_idx = bisect.bisect_left(alphabet_idx[i], a)
                if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

            print(ans) def main():
    n = ni()
    s = list(input())
    q = ni()

    alphabet_idx = {}
    for i in range(26):
        alphabet_idx[i] = []

    for i, si in enumerate(s):
        alphabet_idx[ord(si) - ord("a")].append(i)

    for _ in range(q):
        qi, a, b = input().split()
        qi, a = int(qi), int(a)

        if qi == 1:
            a -= 1
            if s[a] == b:
                continue
            del_char = ord(s[a]) - ord("a")
            del_idx = bisect.bisect_left(alphabet_idx[del_char], a)
            del alphabet_idx[del_char][del_idx]

            insert_char = ord(b) - ord("a")
            insert_idx = bisect.bisect_left(alphabet_idx[insert_char], a)
            alphabet_idx[insert_char].insert(insert_idx, a)

            s[a] = b

        if qi == 2:
            b = int(b)
            a -= 1
            b -= 1
            ans = 0

            for i in range(26):
                a_idx = bisect.bisect_left(alphabet_idx[i], a)
                if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

            print(ans) main ni = lambda: int(sys.stdin.readline()) lambda: int(sys.stdin.readline()) ni MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD na = lambda: list(map(int, sys.stdin.readline().split())) lambda: list(map(int, sys.stdin.readline().split())) na
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    s = list(input())
    q = ni()

    alphabet_idx = {}
    for i in range(26):
        alphabet_idx[i] = []

    for i, si in enumerate(s):
        alphabet_idx[ord(si) - ord("a")].append(i)

    for _ in range(q):
        qi, a, b = input().split()
        qi, a = int(qi), int(a)

        if qi == 1:
            a -= 1
            if s[a] == b:
                continue
            del_char = ord(s[a]) - ord("a")
            del_idx = bisect.bisect_left(alphabet_idx[del_char], a)
            del alphabet_idx[del_char][del_idx]

            insert_char = ord(b) - ord("a")
            insert_idx = bisect.bisect_left(alphabet_idx[insert_char], a)
            alphabet_idx[insert_char].insert(insert_idx, a)

            s[a] = b

        if qi == 2:
            b = int(b)
            a -= 1
            b -= 1
            ans = 0

            for i in range(26):
                a_idx = bisect.bisect_left(alphabet_idx[i], a)
                if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

            print(ans)


if __name__ == '__main__':
    main()
