import bisect
from collections import defaultdict

N = int(input())
S = list(input())
Q = int(input())

alpha_dic = defaultdict(list)

for i, s in enumerate(S):
    alpha_dic[s].append(i)

for _ in range(Q):
    l, m, n = input().split()

    if l == '1':
        m = int(m) - 1
        c = S[m]

        if c == n:
            continue
        else:
            i = bisect.bisect_left(alpha_dic[c], m)
            del alpha_dic[c][i]

            bisect.insort_left(alpha_dic[n], m)
            S[m] = n
    else:
        m, n = int(m) - 1, int(n) - 1

        cnt = 0
        for _, val in alpha_dic.items():
            if not val:
                continue

            left_idx = bisect.bisect_left(val, m)
            right_idx = bisect.bisect_left(val, n)
            l = len(val)

            if left_idx > right_idx or (left_idx == right_idx and left_idx == l) or (left_idx == right_idx and val[left_idx] != m and val[right_idx] != n):
                continue

            cnt += 1

        print(cnt) import bisect bisect from collections import defaultdict N = int(input()) N int(input()) int input() input S = list(input()) S list(input()) list input() input Q = int(input()) Q int(input()) int input() input alpha_dic = defaultdict(list) alpha_dic defaultdict(list) defaultdict list for i, s in enumerate(S):
    alpha_dic[s].append(i) i s enumerate(S) enumerate S alpha_dic[s].append(i) [s].append [s] alpha_dic s append i for _ in range(Q):
    l, m, n = input().split()

    if l == '1':
        m = int(m) - 1
        c = S[m]

        if c == n:
            continue
        else:
            i = bisect.bisect_left(alpha_dic[c], m)
            del alpha_dic[c][i]

            bisect.insort_left(alpha_dic[n], m)
            S[m] = n
    else:
        m, n = int(m) - 1, int(n) - 1

        cnt = 0
        for _, val in alpha_dic.items():
            if not val:
                continue

            left_idx = bisect.bisect_left(val, m)
            right_idx = bisect.bisect_left(val, n)
            l = len(val)

            if left_idx > right_idx or (left_idx == right_idx and left_idx == l) or (left_idx == right_idx and val[left_idx] != m and val[right_idx] != n):
                continue

            cnt += 1

        print(cnt) _ range(Q) range Q l, m, n = input().split() l input().split() ().split () input split m n if l == '1':
        m = int(m) - 1
        c = S[m]

        if c == n:
            continue
        else:
            i = bisect.bisect_left(alpha_dic[c], m)
            del alpha_dic[c][i]

            bisect.insort_left(alpha_dic[n], m)
            S[m] = n
    else:
        m, n = int(m) - 1, int(n) - 1

        cnt = 0
        for _, val in alpha_dic.items():
            if not val:
                continue

            left_idx = bisect.bisect_left(val, m)
            right_idx = bisect.bisect_left(val, n)
            l = len(val)

            if left_idx > right_idx or (left_idx == right_idx and left_idx == l) or (left_idx == right_idx and val[left_idx] != m and val[right_idx] != n):
                continue

            cnt += 1

        print(cnt) l == '1' l '1' m = int(m) - 1 m int(m) - 1 int(m) int m 1 c = S[m] c S[m] S m if c == n:
            continue
        else:
            i = bisect.bisect_left(alpha_dic[c], m)
            del alpha_dic[c][i]

            bisect.insort_left(alpha_dic[n], m)
            S[m] = n
     c == n c n continue i = bisect.bisect_left(alpha_dic[c], m) i bisect.bisect_left(alpha_dic[c], m) bisect.bisect_left bisect bisect_left alpha_dic[c] alpha_dic c m del alpha_dic[c][i] alpha_dic[c][i] [c] alpha_dic c i bisect.insort_left(alpha_dic[n], m) bisect.insort_left bisect insort_left alpha_dic[n] alpha_dic n m S[m] = n S[m] S m n m, n = int(m) - 1, int(n) - 1 m int(m) - 1 int(m) int m 1 n int(n) - 1 int(n) int n 1 cnt = 0 cnt 0 for _, val in alpha_dic.items():
            if not val:
                continue

            left_idx = bisect.bisect_left(val, m)
            right_idx = bisect.bisect_left(val, n)
            l = len(val)

            if left_idx > right_idx or (left_idx == right_idx and left_idx == l) or (left_idx == right_idx and val[left_idx] != m and val[right_idx] != n):
                continue

            cnt += 1

         _ val alpha_dic.items() alpha_dic.items alpha_dic items if not val:
                continue

             not val val continue left_idx = bisect.bisect_left(val, m) left_idx bisect.bisect_left(val, m) bisect.bisect_left bisect bisect_left val m right_idx = bisect.bisect_left(val, n) right_idx bisect.bisect_left(val, n) bisect.bisect_left bisect bisect_left val n l = len(val) l len(val) len val if left_idx > right_idx or (left_idx == right_idx and left_idx == l) or (left_idx == right_idx and val[left_idx] != m and val[right_idx] != n):
                continue

             left_idx > right_idx or (left_idx == right_idx and left_idx == l) or (left_idx == right_idx and val[left_idx] != m and val[right_idx] != n) left_idx > right_idx or (left_idx == right_idx and left_idx == l) left_idx > right_idx left_idx right_idx left_idx == right_idx and left_idx == l left_idx == right_idx left_idx right_idx left_idx == l left_idx l left_idx == right_idx and val[left_idx] != m and val[right_idx] != n left_idx == right_idx and val[left_idx] != m left_idx == right_idx left_idx right_idx val[left_idx] != m val[left_idx] val left_idx m val[right_idx] != n val[right_idx] val right_idx n continue cnt += 1 cnt 1 print(cnt) print cnt S = list(input()) list(input()) S left_idx = bisect.bisect_left(val, m) bisect.bisect_left(val, m) left_idx n = input().split() input().split() n n = int(m) - 1, int(n) - 1 int(n) - 1 n m = int(m) - 1 int(m) - 1 m cnt += 1 1 cnt l, m, n = input().split() input().split() l i = bisect.bisect_left(alpha_dic[c], m) bisect.bisect_left(alpha_dic[c], m) i N = int(input()) int(input()) N c = S[m] S[m] c cnt = 0 0 cnt m, n = input().split() input().split() m right_idx = bisect.bisect_left(val, n) bisect.bisect_left(val, n) right_idx Q = int(input()) int(input()) Q alpha_dic = defaultdict(list) defaultdict(list) alpha_dic m, n = int(m) - 1, int(n) - 1 int(m) - 1 m l = len(val) len(val) l
import bisect
from collections import defaultdict

N = int(input())
S = list(input())
Q = int(input())

alpha_dic = defaultdict(list)

for i, s in enumerate(S):
    alpha_dic[s].append(i)

for _ in range(Q):
    l, m, n = input().split()

    if l == '1':
        m = int(m) - 1
        c = S[m]

        if c == n:
            continue
        else:
            i = bisect.bisect_left(alpha_dic[c], m)
            del alpha_dic[c][i]

            bisect.insort_left(alpha_dic[n], m)
            S[m] = n
    else:
        m, n = int(m) - 1, int(n) - 1

        cnt = 0
        for _, val in alpha_dic.items():
            if not val:
                continue

            left_idx = bisect.bisect_left(val, m)
            right_idx = bisect.bisect_left(val, n)
            l = len(val)

            if left_idx > right_idx or (left_idx == right_idx and left_idx == l) or (left_idx == right_idx and val[left_idx] != m and val[right_idx] != n):
                continue

            cnt += 1

        print(cnt)
