import bisect
import sys
def input(): return sys.stdin.readline().rstrip()

n = int(input())
s = list(input())
q = int(input())

char_idx = [[] for _ in range(26)]
for i in range(n):
    char_idx[ord(s[i])-ord('a')].append(i)
# print(char_idx)

query = [input().split() for _ in range(q)]
# print(query)

for t, a, b in query:
    if t=='1':
        i = int(a) - 1
        if s[i] == b:
            continue
        else:
            idx = bisect.bisect_left(char_idx[ord(s[i])-ord('a')], i)
            if char_idx[ord(s[i])-ord('a')][idx] == i:
                del char_idx[ord(s[i])-ord('a')][idx]
            bisect.insort_left(char_idx[ord(b)-ord('a')], i)
            s[i] = b
    else:
        l = int(a) - 1
        r = int(b) - 1
        ans = 0
        for i in range(26):
            if len(char_idx[i]) == 0:
                continue
            it = bisect.bisect_left(char_idx[i], l)
            if it < len(char_idx[i]) and char_idx[i][it] <= r:
                ans += 1
        print(ans) import bisect bisect import sys sys def input(): return sys.stdin.readline().rstrip() input 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 [] for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [] char_idx = [[] for _ in range(26)] char_idx [[] for _ in range(26)] for i in range(n):
    char_idx[ord(s[i])-ord('a')].append(i)
# print(char_idx) i range(n) range n char_idx[ord(s[i])-ord('a')].append(i) [ord(s[i])-ord('a')].append [ord(s[i])-ord('a')] char_idx ord(s[i])-ord('a') ord(s[i]) ord s[i] s i ord('a') ord 'a' append i input().split() for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) input().split() ().split () input split query = [input().split() for _ in range(q)] query [input().split() for _ in range(q)] for t, a, b in query:
    if t=='1':
        i = int(a) - 1
        if s[i] == b:
            continue
        else:
            idx = bisect.bisect_left(char_idx[ord(s[i])-ord('a')], i)
            if char_idx[ord(s[i])-ord('a')][idx] == i:
                del char_idx[ord(s[i])-ord('a')][idx]
            bisect.insort_left(char_idx[ord(b)-ord('a')], i)
            s[i] = b
    else:
        l = int(a) - 1
        r = int(b) - 1
        ans = 0
        for i in range(26):
            if len(char_idx[i]) == 0:
                continue
            it = bisect.bisect_left(char_idx[i], l)
            if it < len(char_idx[i]) and char_idx[i][it] <= r:
                ans += 1
        print(ans) t a b query if t=='1':
        i = int(a) - 1
        if s[i] == b:
            continue
        else:
            idx = bisect.bisect_left(char_idx[ord(s[i])-ord('a')], i)
            if char_idx[ord(s[i])-ord('a')][idx] == i:
                del char_idx[ord(s[i])-ord('a')][idx]
            bisect.insort_left(char_idx[ord(b)-ord('a')], i)
            s[i] = b
    else:
        l = int(a) - 1
        r = int(b) - 1
        ans = 0
        for i in range(26):
            if len(char_idx[i]) == 0:
                continue
            it = bisect.bisect_left(char_idx[i], l)
            if it < len(char_idx[i]) and char_idx[i][it] <= r:
                ans += 1
        print(ans) t=='1' t '1' i = int(a) - 1 i int(a) - 1 int(a) int a 1 if s[i] == b:
            continue
        else:
            idx = bisect.bisect_left(char_idx[ord(s[i])-ord('a')], i)
            if char_idx[ord(s[i])-ord('a')][idx] == i:
                del char_idx[ord(s[i])-ord('a')][idx]
            bisect.insort_left(char_idx[ord(b)-ord('a')], i)
            s[i] = b
     s[i] == b s[i] s i b continue idx = bisect.bisect_left(char_idx[ord(s[i])-ord('a')], i) idx bisect.bisect_left(char_idx[ord(s[i])-ord('a')], i) bisect.bisect_left bisect bisect_left char_idx[ord(s[i])-ord('a')] char_idx ord(s[i])-ord('a') ord(s[i]) ord s[i] s i ord('a') ord 'a' i if char_idx[ord(s[i])-ord('a')][idx] == i:
                del char_idx[ord(s[i])-ord('a')][idx]
             char_idx[ord(s[i])-ord('a')][idx] == i char_idx[ord(s[i])-ord('a')][idx] [ord(s[i])-ord('a')] char_idx ord(s[i])-ord('a') ord(s[i]) ord s[i] s i ord('a') ord 'a' idx i del char_idx[ord(s[i])-ord('a')][idx] char_idx[ord(s[i])-ord('a')][idx] [ord(s[i])-ord('a')] char_idx ord(s[i])-ord('a') ord(s[i]) ord s[i] s i ord('a') ord 'a' idx bisect.insort_left(char_idx[ord(b)-ord('a')], i) bisect.insort_left bisect insort_left char_idx[ord(b)-ord('a')] char_idx ord(b)-ord('a') ord(b) ord b ord('a') ord 'a' i s[i] = b s[i] s i b l = int(a) - 1 l int(a) - 1 int(a) int a 1 r = int(b) - 1 r int(b) - 1 int(b) int b 1 ans = 0 ans 0 for i in range(26):
            if len(char_idx[i]) == 0:
                continue
            it = bisect.bisect_left(char_idx[i], l)
            if it < len(char_idx[i]) and char_idx[i][it] <= r:
                ans += 1
         i range(26) range 26 if len(char_idx[i]) == 0:
                continue
             len(char_idx[i]) == 0 len(char_idx[i]) len char_idx[i] char_idx i 0 continue it = bisect.bisect_left(char_idx[i], l) it bisect.bisect_left(char_idx[i], l) bisect.bisect_left bisect bisect_left char_idx[i] char_idx i l if it < len(char_idx[i]) and char_idx[i][it] <= r:
                ans += 1
         it < len(char_idx[i]) and char_idx[i][it] <= r it < len(char_idx[i]) it len(char_idx[i]) len char_idx[i] char_idx i char_idx[i][it] <= r char_idx[i][it] [i] char_idx i it r ans += 1 ans 1 print(ans) print ans s = list(input()) list(input()) s def input(): return sys.stdin.readline().rstrip() def input(): return sys.stdin.readline().rstrip() input ans += 1 1 ans it = bisect.bisect_left(char_idx[i], l) bisect.bisect_left(char_idx[i], l) it idx = bisect.bisect_left(char_idx[ord(s[i])-ord('a')], i) bisect.bisect_left(char_idx[ord(s[i])-ord('a')], i) idx i = int(a) - 1 int(a) - 1 i char_idx = [[] for _ in range(26)] [[] for _ in range(26)] char_idx r = int(b) - 1 int(b) - 1 r query = [input().split() for _ in range(q)] [input().split() for _ in range(q)] query ans = 0 0 ans l = int(a) - 1 int(a) - 1 l n = int(input()) int(input()) n q = int(input()) int(input()) q
import bisect
import sys
def input(): return sys.stdin.readline().rstrip()

n = int(input())
s = list(input())
q = int(input())

char_idx = [[] for _ in range(26)]
for i in range(n):
    char_idx[ord(s[i])-ord('a')].append(i)
# print(char_idx)

query = [input().split() for _ in range(q)]
# print(query)

for t, a, b in query:
    if t=='1':
        i = int(a) - 1
        if s[i] == b:
            continue
        else:
            idx = bisect.bisect_left(char_idx[ord(s[i])-ord('a')], i)
            if char_idx[ord(s[i])-ord('a')][idx] == i:
                del char_idx[ord(s[i])-ord('a')][idx]
            bisect.insort_left(char_idx[ord(b)-ord('a')], i)
            s[i] = b
    else:
        l = int(a) - 1
        r = int(b) - 1
        ans = 0
        for i in range(26):
            if len(char_idx[i]) == 0:
                continue
            it = bisect.bisect_left(char_idx[i], l)
            if it < len(char_idx[i]) and char_idx[i][it] <= r:
                ans += 1
        print(ans)
