# -*- coding: utf-8 -*-

'''
7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7
'''

# from helper import elapsed_time
from bisect import bisect_left, insort_left


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

# a-zまでの26文字に対して、s文字列の各文字に該当するindexを格納しておく
d = {i: [] for i in range(26)}
for i, c in enumerate(s):
    d[ord(c) - ord("a")].append(i)


# @elapsed_time
def convert(d: dict, s: list, q1: int, q2: str):
    if s[q1] == q2:
        return d, s

    didx_before = ord(s[q1]) - ord("a")
    didx_after = ord(q2) - ord("a")

    idx = bisect_left(d[didx_before], q1)
    d[didx_before].pop(idx)
    s[q1] = q2
    insort_left(d[didx_after], q1)

    return d, s


# @elapsed_time
def calc(d: dict, q1: int, q2: int):
    ans = 0
    for i in range(26):
        idx = bisect_left(d[i], q1)
        if d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1:
            ans += 1

    return ans


for _ in range(Q):
    q, q1, q2 = input().split()
    q = int(q)
    if q == 1:
        d, s = convert(d, s, int(q1) - 1, q2)
    if q == 2:
        print(calc(d, int(q1) - 1, int(q2) - 1)) '''
7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7
''' from bisect import bisect_left, insort_left 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 i: [] for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) i [] d = {i: [] for i in range(26)} d {i: [] for i in range(26)} for i, c in enumerate(s):
    d[ord(c) - ord("a")].append(i)


# @elapsed_time i c enumerate(s) enumerate s d[ord(c) - ord("a")].append(i) [ord(c) - ord("a")].append [ord(c) - ord("a")] d ord(c) - ord("a") ord(c) ord c ord("a") ord "a" append i def convert(d: dict, s: list, q1: int, q2: str):
    if s[q1] == q2:
        return d, s

    didx_before = ord(s[q1]) - ord("a")
    didx_after = ord(q2) - ord("a")

    idx = bisect_left(d[didx_before], q1)
    d[didx_before].pop(idx)
    s[q1] = q2
    insort_left(d[didx_after], q1)

    return d, s


# @elapsed_time convert if s[q1] == q2:
        return d, s

     s[q1] == q2 s[q1] s q1 q2 return d, s return d, s d s didx_before = ord(s[q1]) - ord("a") didx_before ord(s[q1]) - ord("a") ord(s[q1]) ord s[q1] s q1 ord("a") ord "a" didx_after = ord(q2) - ord("a") didx_after ord(q2) - ord("a") ord(q2) ord q2 ord("a") ord "a" idx = bisect_left(d[didx_before], q1) idx bisect_left(d[didx_before], q1) bisect_left d[didx_before] d didx_before q1 d[didx_before].pop(idx) [didx_before].pop [didx_before] d didx_before pop idx s[q1] = q2 s[q1] s q1 q2 insort_left(d[didx_after], q1) insort_left d[didx_after] d didx_after q1 return d, s return d, s d s d: dict d s: list s q1: int q1 q2: str q2 def calc(d: dict, q1: int, q2: int):
    ans = 0
    for i in range(26):
        idx = bisect_left(d[i], q1)
        if d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1:
            ans += 1

    return ans calc ans = 0 ans 0 for i in range(26):
        idx = bisect_left(d[i], q1)
        if d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1:
            ans += 1

     i range(26) range 26 idx = bisect_left(d[i], q1) idx bisect_left(d[i], q1) bisect_left d[i] d i q1 if d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1:
            ans += 1

     d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1 d[i] and q1 <= d[i][-1] d[i] d i q1 <= d[i][-1] q1 d[i][-1] [i] d i -1 d[i][idx] < q2 + 1 d[i][idx] [i] d i idx q2 + 1 q2 1 ans += 1 ans 1 return ans ans d: dict d q1: int q1 q2: int q2 for _ in range(Q):
    q, q1, q2 = input().split()
    q = int(q)
    if q == 1:
        d, s = convert(d, s, int(q1) - 1, q2)
    if q == 2:
        print(calc(d, int(q1) - 1, int(q2) - 1)) _ range(Q) range Q q, q1, q2 = input().split() q input().split() ().split () input split q1 q2 q = int(q) q int(q) int q if q == 1:
        d, s = convert(d, s, int(q1) - 1, q2)
     q == 1 q 1 d, s = convert(d, s, int(q1) - 1, q2) d convert(d, s, int(q1) - 1, q2) convert d s int(q1) - 1 int(q1) int q1 1 q2 s if q == 2:
        print(calc(d, int(q1) - 1, int(q2) - 1)) q == 2 q 2 print(calc(d, int(q1) - 1, int(q2) - 1)) print calc(d, int(q1) - 1, int(q2) - 1) calc d int(q1) - 1 int(q1) int q1 1 int(q2) - 1 int(q2) int q2 1 s = list(input()) list(input()) s d, s = convert(d, s, int(q1) - 1, q2) convert(d, s, int(q1) - 1, q2) d q2 = input().split() input().split() q2 q, q1, q2 = input().split() input().split() q Q = int(input()) int(input()) Q d = {i: [] for i in range(26)} {i: [] for i in range(26)} d N = int(input()) int(input()) N def calc(d: dict, q1: int, q2: int):
    ans = 0
    for i in range(26):
        idx = bisect_left(d[i], q1)
        if d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1:
            ans += 1

    return ans def calc(d: dict, q1: int, q2: int):
    ans = 0
    for i in range(26):
        idx = bisect_left(d[i], q1)
        if d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1:
            ans += 1

    return ans calc q1, q2 = input().split() input().split() q1 s = convert(d, s, int(q1) - 1, q2) convert(d, s, int(q1) - 1, q2) s q = int(q) int(q) q def convert(d: dict, s: list, q1: int, q2: str):
    if s[q1] == q2:
        return d, s

    didx_before = ord(s[q1]) - ord("a")
    didx_after = ord(q2) - ord("a")

    idx = bisect_left(d[didx_before], q1)
    d[didx_before].pop(idx)
    s[q1] = q2
    insort_left(d[didx_after], q1)

    return d, s


# @elapsed_time def convert(d: dict, s: list, q1: int, q2: str):
    if s[q1] == q2:
        return d, s

    didx_before = ord(s[q1]) - ord("a")
    didx_after = ord(q2) - ord("a")

    idx = bisect_left(d[didx_before], q1)
    d[didx_before].pop(idx)
    s[q1] = q2
    insort_left(d[didx_after], q1)

    return d, s


# @elapsed_time convert
# -*- coding: utf-8 -*-

'''
7
abcdbbd
6
2 3 6
1 5 z
2 1 1
1 4 a
1 7 d
2 1 7
'''

# from helper import elapsed_time
from bisect import bisect_left, insort_left


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

# a-zまでの26文字に対して、s文字列の各文字に該当するindexを格納しておく
d = {i: [] for i in range(26)}
for i, c in enumerate(s):
    d[ord(c) - ord("a")].append(i)


# @elapsed_time
def convert(d: dict, s: list, q1: int, q2: str):
    if s[q1] == q2:
        return d, s

    didx_before = ord(s[q1]) - ord("a")
    didx_after = ord(q2) - ord("a")

    idx = bisect_left(d[didx_before], q1)
    d[didx_before].pop(idx)
    s[q1] = q2
    insort_left(d[didx_after], q1)

    return d, s


# @elapsed_time
def calc(d: dict, q1: int, q2: int):
    ans = 0
    for i in range(26):
        idx = bisect_left(d[i], q1)
        if d[i] and q1 <= d[i][-1] and d[i][idx] < q2 + 1:
            ans += 1

    return ans


for _ in range(Q):
    q, q1, q2 = input().split()
    q = int(q)
    if q == 1:
        d, s = convert(d, s, int(q1) - 1, q2)
    if q == 2:
        print(calc(d, int(q1) - 1, int(q2) - 1))
