import sys
import math
import bisect
def input():
    return sys.stdin.readline()[:-1]

n=int(input())
s=list(input())
q=int(input())
ans=[]
dic = {}

for i in range(97,97+26):
    dic[chr(i)]=[]

for num,i in enumerate(s):
    dic[i].append(num)

for i in range(q):
    num,l,r = map(str,input().split())
    if int(num)==1:
        l=int(l)-1
        if s[l] == r:
            continue
        else:
            dic[s[l]].pop(bisect.bisect_left(dic[s[l]],l))
            bisect.insort_left(dic[r],l)
            s[l] = r
    else:
        cnt=0
        l=int(l)
        r=int(r)
        for li in dic.values():
            ind = bisect.bisect_left(li,l-1)
            if ind>=len(li):continue
            if li[ind]<=r-1:
                cnt+=1
        ans.append(cnt)

print(*ans,sep="\n") import sys sys import math math import bisect bisect def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 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 ans=[] ans [] dic = {} dic {} for i in range(97,97+26):
    dic[chr(i)]=[] i range(97,97+26) range 97 97+26 97 26 dic[chr(i)]=[] dic[chr(i)] dic chr(i) chr i [] for num,i in enumerate(s):
    dic[i].append(num) num i enumerate(s) enumerate s dic[i].append(num) [i].append [i] dic i append num for i in range(q):
    num,l,r = map(str,input().split())
    if int(num)==1:
        l=int(l)-1
        if s[l] == r:
            continue
        else:
            dic[s[l]].pop(bisect.bisect_left(dic[s[l]],l))
            bisect.insort_left(dic[r],l)
            s[l] = r
    else:
        cnt=0
        l=int(l)
        r=int(r)
        for li in dic.values():
            ind = bisect.bisect_left(li,l-1)
            if ind>=len(li):continue
            if li[ind]<=r-1:
                cnt+=1
        ans.append(cnt) i range(q) range q num,l,r = map(str,input().split()) num map(str,input().split()) map str input().split() ().split () input split l r if int(num)==1:
        l=int(l)-1
        if s[l] == r:
            continue
        else:
            dic[s[l]].pop(bisect.bisect_left(dic[s[l]],l))
            bisect.insort_left(dic[r],l)
            s[l] = r
    else:
        cnt=0
        l=int(l)
        r=int(r)
        for li in dic.values():
            ind = bisect.bisect_left(li,l-1)
            if ind>=len(li):continue
            if li[ind]<=r-1:
                cnt+=1
        ans.append(cnt) int(num)==1 int(num) int num 1 l=int(l)-1 l int(l)-1 int(l) int l 1 if s[l] == r:
            continue
        else:
            dic[s[l]].pop(bisect.bisect_left(dic[s[l]],l))
            bisect.insort_left(dic[r],l)
            s[l] = r
     s[l] == r s[l] s l r continue dic[s[l]].pop(bisect.bisect_left(dic[s[l]],l)) [s[l]].pop [s[l]] dic s[l] s l pop bisect.bisect_left(dic[s[l]],l) bisect.bisect_left bisect bisect_left dic[s[l]] dic s[l] s l l bisect.insort_left(dic[r],l) bisect.insort_left bisect insort_left dic[r] dic r l s[l] = r s[l] s l r cnt=0 cnt 0 l=int(l) l int(l) int l r=int(r) r int(r) int r for li in dic.values():
            ind = bisect.bisect_left(li,l-1)
            if ind>=len(li):continue
            if li[ind]<=r-1:
                cnt+=1
         li dic.values() dic.values dic values ind = bisect.bisect_left(li,l-1) ind bisect.bisect_left(li,l-1) bisect.bisect_left bisect bisect_left li l-1 l 1 if ind>=len(li):continue
             ind>=len(li) ind len(li) len li if li[ind]<=r-1:
                cnt+=1
         li[ind]<=r-1 li[ind] li ind r-1 r 1 cnt+=1 cnt 1 ans.append(cnt) ans.append ans append cnt print(*ans,sep="\n") print *ans ans sep="\n" sep "\n" ans=[] [] ans dic = {} {} dic q=int(input()) int(input()) q l=int(l) int(l) l ind = bisect.bisect_left(li,l-1) bisect.bisect_left(li,l-1) ind n=int(input()) int(input()) n r=int(r) int(r) r cnt+=1 1 cnt def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input r = map(str,input().split()) map(str,input().split()) r l=int(l)-1 int(l)-1 l cnt=0 0 cnt l,r = map(str,input().split()) map(str,input().split()) l s=list(input()) list(input()) s num,l,r = map(str,input().split()) map(str,input().split()) num
import sys
import math
import bisect
def input():
    return sys.stdin.readline()[:-1]

n=int(input())
s=list(input())
q=int(input())
ans=[]
dic = {}

for i in range(97,97+26):
    dic[chr(i)]=[]

for num,i in enumerate(s):
    dic[i].append(num)

for i in range(q):
    num,l,r = map(str,input().split())
    if int(num)==1:
        l=int(l)-1
        if s[l] == r:
            continue
        else:
            dic[s[l]].pop(bisect.bisect_left(dic[s[l]],l))
            bisect.insort_left(dic[r],l)
            s[l] = r
    else:
        cnt=0
        l=int(l)
        r=int(r)
        for li in dic.values():
            ind = bisect.bisect_left(li,l-1)
            if ind>=len(li):continue
            if li[ind]<=r-1:
                cnt+=1
        ans.append(cnt)

print(*ans,sep="\n")
