# coding: utf-8
import sys
from bisect import bisect_left, bisect_right, insort_left
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 各アルファベットのindexのリストを作り,bisect_left()
N = ir()
S = list(sr())
dic = defaultdict(list)
for i, s in enumerate(S):
    dic[s].append(i)

Q = ir()
for _ in range(Q):
    a, b, c = sr().split()
    if a == '1':
        b = int(b) - 1
        if S[b] == c:
            continue
        dic[S[b]].remove(b)
        insort_left(dic[c], b)
        S[b] = c
    else:
        b = int(b) - 1; c = int(c) - 1
        kind = 0
        for x in range(26):
            word = chr(ord('a')+x)
            if len(dic[word]) == 0:
                continue
            i = bisect_left(dic[word], b)
            j = bisect_right(dic[word], c)
            if i != j:
                kind += 1
        print(kind)

# 07 import sys sys from bisect import bisect_left, bisect_right, insort_left from collections import defaultdict sr = lambda: sys.stdin.readline().rstrip() sr lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip ir = lambda: int(sr()) ir lambda: int(sr()) int(sr()) int sr() sr lr = lambda: list(map(int, sr().split())) lr lambda: list(map(int, sr().split())) list(map(int, sr().split())) list map(int, sr().split()) map int sr().split() ().split () sr split N = ir() N ir() ir S = list(sr()) S list(sr()) list sr() sr dic = defaultdict(list) dic defaultdict(list) defaultdict list for i, s in enumerate(S):
    dic[s].append(i) i s enumerate(S) enumerate S dic[s].append(i) [s].append [s] dic s append i Q = ir() Q ir() ir for _ in range(Q):
    a, b, c = sr().split()
    if a == '1':
        b = int(b) - 1
        if S[b] == c:
            continue
        dic[S[b]].remove(b)
        insort_left(dic[c], b)
        S[b] = c
    else:
        b = int(b) - 1; c = int(c) - 1
        kind = 0
        for x in range(26):
            word = chr(ord('a')+x)
            if len(dic[word]) == 0:
                continue
            i = bisect_left(dic[word], b)
            j = bisect_right(dic[word], c)
            if i != j:
                kind += 1
        print(kind)

# 07 _ range(Q) range Q a, b, c = sr().split() a sr().split() ().split () sr split b c if a == '1':
        b = int(b) - 1
        if S[b] == c:
            continue
        dic[S[b]].remove(b)
        insort_left(dic[c], b)
        S[b] = c
    else:
        b = int(b) - 1; c = int(c) - 1
        kind = 0
        for x in range(26):
            word = chr(ord('a')+x)
            if len(dic[word]) == 0:
                continue
            i = bisect_left(dic[word], b)
            j = bisect_right(dic[word], c)
            if i != j:
                kind += 1
        print(kind)

# 07 a == '1' a '1' b = int(b) - 1 b int(b) - 1 int(b) int b 1 if S[b] == c:
            continue
         S[b] == c S[b] S b c continue dic[S[b]].remove(b) [S[b]].remove [S[b]] dic S[b] S b remove b insort_left(dic[c], b) insort_left dic[c] dic c b S[b] = c S[b] S b c b = int(b) - 1 b int(b) - 1 int(b) int b 1 c = int(c) - 1 c int(c) - 1 int(c) int c 1 kind = 0 kind 0 for x in range(26):
            word = chr(ord('a')+x)
            if len(dic[word]) == 0:
                continue
            i = bisect_left(dic[word], b)
            j = bisect_right(dic[word], c)
            if i != j:
                kind += 1
         x range(26) range 26 word = chr(ord('a')+x) word chr(ord('a')+x) chr ord('a')+x ord('a') ord 'a' x if len(dic[word]) == 0:
                continue
             len(dic[word]) == 0 len(dic[word]) len dic[word] dic word 0 continue i = bisect_left(dic[word], b) i bisect_left(dic[word], b) bisect_left dic[word] dic word b j = bisect_right(dic[word], c) j bisect_right(dic[word], c) bisect_right dic[word] dic word c if i != j:
                kind += 1
         i != j i j kind += 1 kind 1 print(kind) print kind Q = ir() ir() Q c = sr().split() sr().split() c ir = lambda: int(sr()) lambda: int(sr()) ir i = bisect_left(dic[word], b) bisect_left(dic[word], b) i S = list(sr()) list(sr()) S dic = defaultdict(list) defaultdict(list) dic b = int(b) - 1 int(b) - 1 b lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr N = ir() ir() N a, b, c = sr().split() sr().split() a word = chr(ord('a')+x) chr(ord('a')+x) word kind += 1 1 kind b, c = sr().split() sr().split() b kind = 0 0 kind j = bisect_right(dic[word], c) bisect_right(dic[word], c) j c = int(c) - 1 int(c) - 1 c b = int(b) - 1 int(b) - 1 b sr = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() sr
# coding: utf-8
import sys
from bisect import bisect_left, bisect_right, insort_left
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 各アルファベットのindexのリストを作り,bisect_left()
N = ir()
S = list(sr())
dic = defaultdict(list)
for i, s in enumerate(S):
    dic[s].append(i)

Q = ir()
for _ in range(Q):
    a, b, c = sr().split()
    if a == '1':
        b = int(b) - 1
        if S[b] == c:
            continue
        dic[S[b]].remove(b)
        insort_left(dic[c], b)
        S[b] = c
    else:
        b = int(b) - 1; c = int(c) - 1
        kind = 0
        for x in range(26):
            word = chr(ord('a')+x)
            if len(dic[word]) == 0:
                continue
            i = bisect_left(dic[word], b)
            j = bisect_right(dic[word], c)
            if i != j:
                kind += 1
        print(kind)

# 07