from collections import defaultdict
import bisect

n = int(input())
s = input()
S = []
cnt_ch = defaultdict(list)
for i in range(n):
    S.append(s[i])
    cnt_ch[s[i]].append(i)
    
    
    
    
q = int(input())
for i in range(q):
    qw = input()
    if qw[0] == "1":
        qw = qw[2:]
        i, ch = map(str, qw.split())
        if S[int(i) - 1] == ch:
            continue
        remove = bisect.bisect_left(cnt_ch[S[int(i) - 1]], int(i) - 1)
        del cnt_ch[S[int(i) - 1]][remove]
        S[int(i) - 1] = ch
        if not cnt_ch[ch]:
            cnt_ch[ch].append(int(i) - 1)
            continue
        bisect.insort_left(cnt_ch[ch], int(i) - 1)
        
        
    else:
        #print(cnt_ch)
        qw = qw[2:]
        l, r = map(int, qw.split())
        cnt = 0
        for i in range(ord("a"),ord("a") + 26):
            if not cnt_ch[chr(i)]:
                continue
            edge = bisect.bisect_left(cnt_ch[chr(i)], l - 1)
            #print(cnt_ch[chr(i)][edge - 1:])
            #if bisect.bisect_left(cnt_ch[chr(i)][edge:], i) < r:
            #print(cnt_ch[chr(i)])
            #print(l, r)
            #print(edge)
            if edge < len(cnt_ch[chr(i)]):
                if cnt_ch[chr(i)][edge] < r:
                    cnt += 1
            #print(cnt, "cnt", chr(i))
        print(cnt)
        
         from collections import defaultdict import bisect bisect n = int(input()) n int(input()) int input() input s = input() s input() input S = [] S [] cnt_ch = defaultdict(list) cnt_ch defaultdict(list) defaultdict list for i in range(n):
    S.append(s[i])
    cnt_ch[s[i]].append(i)
    
    
    
     i range(n) range n S.append(s[i]) S.append S append s[i] s i cnt_ch[s[i]].append(i) [s[i]].append [s[i]] cnt_ch s[i] s i append i q = int(input()) q int(input()) int input() input for i in range(q):
    qw = input()
    if qw[0] == "1":
        qw = qw[2:]
        i, ch = map(str, qw.split())
        if S[int(i) - 1] == ch:
            continue
        remove = bisect.bisect_left(cnt_ch[S[int(i) - 1]], int(i) - 1)
        del cnt_ch[S[int(i) - 1]][remove]
        S[int(i) - 1] = ch
        if not cnt_ch[ch]:
            cnt_ch[ch].append(int(i) - 1)
            continue
        bisect.insort_left(cnt_ch[ch], int(i) - 1)
        
        
    else:
        #print(cnt_ch)
        qw = qw[2:]
        l, r = map(int, qw.split())
        cnt = 0
        for i in range(ord("a"),ord("a") + 26):
            if not cnt_ch[chr(i)]:
                continue
            edge = bisect.bisect_left(cnt_ch[chr(i)], l - 1)
            #print(cnt_ch[chr(i)][edge - 1:])
            #if bisect.bisect_left(cnt_ch[chr(i)][edge:], i) < r:
            #print(cnt_ch[chr(i)])
            #print(l, r)
            #print(edge)
            if edge < len(cnt_ch[chr(i)]):
                if cnt_ch[chr(i)][edge] < r:
                    cnt += 1
            #print(cnt, "cnt", chr(i))
        print(cnt)
        
         i range(q) range q qw = input() qw input() input if qw[0] == "1":
        qw = qw[2:]
        i, ch = map(str, qw.split())
        if S[int(i) - 1] == ch:
            continue
        remove = bisect.bisect_left(cnt_ch[S[int(i) - 1]], int(i) - 1)
        del cnt_ch[S[int(i) - 1]][remove]
        S[int(i) - 1] = ch
        if not cnt_ch[ch]:
            cnt_ch[ch].append(int(i) - 1)
            continue
        bisect.insort_left(cnt_ch[ch], int(i) - 1)
        
        
    else:
        #print(cnt_ch)
        qw = qw[2:]
        l, r = map(int, qw.split())
        cnt = 0
        for i in range(ord("a"),ord("a") + 26):
            if not cnt_ch[chr(i)]:
                continue
            edge = bisect.bisect_left(cnt_ch[chr(i)], l - 1)
            #print(cnt_ch[chr(i)][edge - 1:])
            #if bisect.bisect_left(cnt_ch[chr(i)][edge:], i) < r:
            #print(cnt_ch[chr(i)])
            #print(l, r)
            #print(edge)
            if edge < len(cnt_ch[chr(i)]):
                if cnt_ch[chr(i)][edge] < r:
                    cnt += 1
            #print(cnt, "cnt", chr(i))
        print(cnt)
        
         qw[0] == "1" qw[0] qw 0 "1" qw = qw[2:] qw qw[2:] qw 2: 2 i, ch = map(str, qw.split()) i map(str, qw.split()) map str qw.split() qw.split qw split ch if S[int(i) - 1] == ch:
            continue
         S[int(i) - 1] == ch S[int(i) - 1] S int(i) - 1 int(i) int i 1 ch continue remove = bisect.bisect_left(cnt_ch[S[int(i) - 1]], int(i) - 1) remove bisect.bisect_left(cnt_ch[S[int(i) - 1]], int(i) - 1) bisect.bisect_left bisect bisect_left cnt_ch[S[int(i) - 1]] cnt_ch S[int(i) - 1] S int(i) - 1 int(i) int i 1 int(i) - 1 int(i) int i 1 del cnt_ch[S[int(i) - 1]][remove] cnt_ch[S[int(i) - 1]][remove] [S[int(i) - 1]] cnt_ch S[int(i) - 1] S int(i) - 1 int(i) int i 1 remove S[int(i) - 1] = ch S[int(i) - 1] S int(i) - 1 int(i) int i 1 ch if not cnt_ch[ch]:
            cnt_ch[ch].append(int(i) - 1)
            continue
         not cnt_ch[ch] cnt_ch[ch] cnt_ch ch cnt_ch[ch].append(int(i) - 1) [ch].append [ch] cnt_ch ch append int(i) - 1 int(i) int i 1 continue bisect.insort_left(cnt_ch[ch], int(i) - 1) bisect.insort_left bisect insort_left cnt_ch[ch] cnt_ch ch int(i) - 1 int(i) int i 1 qw = qw[2:] qw qw[2:] qw 2: 2 l, r = map(int, qw.split()) l map(int, qw.split()) map int qw.split() qw.split qw split r cnt = 0 cnt 0 for i in range(ord("a"),ord("a") + 26):
            if not cnt_ch[chr(i)]:
                continue
            edge = bisect.bisect_left(cnt_ch[chr(i)], l - 1)
            #print(cnt_ch[chr(i)][edge - 1:])
            #if bisect.bisect_left(cnt_ch[chr(i)][edge:], i) < r:
            #print(cnt_ch[chr(i)])
            #print(l, r)
            #print(edge)
            if edge < len(cnt_ch[chr(i)]):
                if cnt_ch[chr(i)][edge] < r:
                    cnt += 1
            #print(cnt, "cnt", chr(i))
         i range(ord("a"),ord("a") + 26) range ord("a") ord "a" ord("a") + 26 ord("a") ord "a" 26 if not cnt_ch[chr(i)]:
                continue
             not cnt_ch[chr(i)] cnt_ch[chr(i)] cnt_ch chr(i) chr i continue edge = bisect.bisect_left(cnt_ch[chr(i)], l - 1) edge bisect.bisect_left(cnt_ch[chr(i)], l - 1) bisect.bisect_left bisect bisect_left cnt_ch[chr(i)] cnt_ch chr(i) chr i l - 1 l 1 if edge < len(cnt_ch[chr(i)]):
                if cnt_ch[chr(i)][edge] < r:
                    cnt += 1
            #print(cnt, "cnt", chr(i))
         edge < len(cnt_ch[chr(i)]) edge len(cnt_ch[chr(i)]) len cnt_ch[chr(i)] cnt_ch chr(i) chr i if cnt_ch[chr(i)][edge] < r:
                    cnt += 1
            #print(cnt, "cnt", chr(i))
         cnt_ch[chr(i)][edge] < r cnt_ch[chr(i)][edge] [chr(i)] cnt_ch chr(i) chr i edge r cnt += 1 cnt 1 print(cnt) print cnt edge = bisect.bisect_left(cnt_ch[chr(i)], l - 1) bisect.bisect_left(cnt_ch[chr(i)], l - 1) edge l, r = map(int, qw.split()) map(int, qw.split()) l r = map(int, qw.split()) map(int, qw.split()) r cnt = 0 0 cnt qw = qw[2:] qw[2:] qw ch = map(str, qw.split()) map(str, qw.split()) ch q = int(input()) int(input()) q cnt += 1 1 cnt i, ch = map(str, qw.split()) map(str, qw.split()) i qw = qw[2:] qw[2:] qw n = int(input()) int(input()) n s = input() input() s remove = bisect.bisect_left(cnt_ch[S[int(i) - 1]], int(i) - 1) bisect.bisect_left(cnt_ch[S[int(i) - 1]], int(i) - 1) remove cnt_ch = defaultdict(list) defaultdict(list) cnt_ch qw = input() input() qw S = [] [] S
from collections import defaultdict
import bisect

n = int(input())
s = input()
S = []
cnt_ch = defaultdict(list)
for i in range(n):
    S.append(s[i])
    cnt_ch[s[i]].append(i)
    
    
    
    
q = int(input())
for i in range(q):
    qw = input()
    if qw[0] == "1":
        qw = qw[2:]
        i, ch = map(str, qw.split())
        if S[int(i) - 1] == ch:
            continue
        remove = bisect.bisect_left(cnt_ch[S[int(i) - 1]], int(i) - 1)
        del cnt_ch[S[int(i) - 1]][remove]
        S[int(i) - 1] = ch
        if not cnt_ch[ch]:
            cnt_ch[ch].append(int(i) - 1)
            continue
        bisect.insort_left(cnt_ch[ch], int(i) - 1)
        
        
    else:
        #print(cnt_ch)
        qw = qw[2:]
        l, r = map(int, qw.split())
        cnt = 0
        for i in range(ord("a"),ord("a") + 26):
            if not cnt_ch[chr(i)]:
                continue
            edge = bisect.bisect_left(cnt_ch[chr(i)], l - 1)
            #print(cnt_ch[chr(i)][edge - 1:])
            #if bisect.bisect_left(cnt_ch[chr(i)][edge:], i) < r:
            #print(cnt_ch[chr(i)])
            #print(l, r)
            #print(edge)
            if edge < len(cnt_ch[chr(i)]):
                if cnt_ch[chr(i)][edge] < r:
                    cnt += 1
            #print(cnt, "cnt", chr(i))
        print(cnt)
        
        
