
n=int(input())
s=input()

#初期化
ind=1
while 2**ind<=n:
    ind+=1
s+="*"*(2**ind-n)
seg=[]
seg2=[]

from collections import deque
tmp=deque([s])
while len(tmp)>0:
    t=tmp.popleft()
    cnt=0
    for ss in t:
        if ss!="*":
            cnt=cnt|2**(ord(ss)-97)
    seg.append(cnt)
    seg2.append(t)
    if len(t)>1:
        tmp.append(t[:len(t)//2])
        tmp.append(t[len(t)//2:])

#セグ木が出来た！
#print(seg)
#print(seg2)

q=int(input())

def change(i,s):
    #i文字目をsに変更する
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2
    global n,seg,ind
    ii=len(seg)-2**ind+i-1
    seg[ii]=2**(ord(s)-97)
    p=(ii-1)//2
    while 1:
        seg[p]=seg[2*p+1]|seg[2*p+2]
        if p==0:
            break
        p=(p-1)//2

    #print(seg)

from collections import deque


def count(l,r):
    global n,seg,s
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2

    d = deque([(1,len(s),0)])
    ans=0

    while len(d)>0:
        tmp=d.popleft()
        #print(tmp)
        ll,rr,i=tmp[0],tmp[1],tmp[2]
        if l<=ll and rr<=r:
            ans=ans|seg[i]
        elif (ll<=l and l<=rr) or (ll<=r and r<=rr):
            d.append((ll,ll+(rr-ll)//2,2*i+1))
            d.append((ll+(rr-ll)//2+1,rr,2*i+2))

    return str(bin(ans)).count("1")


result=[]


for _ in range(q):
    b,i,c=map(str,input().split())
    if b=="1":
        #i文字目をcに変更
        change(int(i),c)
    else:
        #l文字目からr文字目までに含まれる数
        result.append(count(int(i),int(c)))

for item in result:
    print(item)










    
          n=int(input()) n int(input()) int input() input s=input() s input() input ind=1 ind 1 while 2**ind<=n:
    ind+=1 2**ind<=n 2**ind 2 ind n ind+=1 ind 1 s+="*"*(2**ind-n) s "*"*(2**ind-n) "*" 2**ind-n 2**ind 2 ind n seg=[] seg [] seg2=[] seg2 [] from collections import deque tmp=deque([s]) tmp deque([s]) deque [s] s while len(tmp)>0:
    t=tmp.popleft()
    cnt=0
    for ss in t:
        if ss!="*":
            cnt=cnt|2**(ord(ss)-97)
    seg.append(cnt)
    seg2.append(t)
    if len(t)>1:
        tmp.append(t[:len(t)//2])
        tmp.append(t[len(t)//2:])

#セグ木が出来た！
#print(seg)
#print(seg2) len(tmp)>0 len(tmp) len tmp 0 t=tmp.popleft() t tmp.popleft() tmp.popleft tmp popleft cnt=0 cnt 0 for ss in t:
        if ss!="*":
            cnt=cnt|2**(ord(ss)-97)
     ss t if ss!="*":
            cnt=cnt|2**(ord(ss)-97)
     ss!="*" ss "*" cnt=cnt|2**(ord(ss)-97) cnt cnt|2**(ord(ss)-97) cnt 2**(ord(ss)-97) 2 ord(ss)-97 ord(ss) ord ss 97 seg.append(cnt) seg.append seg append cnt seg2.append(t) seg2.append seg2 append t if len(t)>1:
        tmp.append(t[:len(t)//2])
        tmp.append(t[len(t)//2:])

#セグ木が出来た！
#print(seg)
#print(seg2) len(t)>1 len(t) len t 1 tmp.append(t[:len(t)//2]) tmp.append tmp append t[:len(t)//2] t :len(t)//2 len(t)//2 len(t) len t 2 tmp.append(t[len(t)//2:]) tmp.append tmp append t[len(t)//2:] t len(t)//2: len(t)//2 len(t) len t 2 q=int(input()) q int(input()) int input() input def change(i,s):
    #i文字目をsに変更する
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2
    global n,seg,ind
    ii=len(seg)-2**ind+i-1
    seg[ii]=2**(ord(s)-97)
    p=(ii-1)//2
    while 1:
        seg[p]=seg[2*p+1]|seg[2*p+2]
        if p==0:
            break
        p=(p-1)//2

    #print(seg) change global n,seg,ind ii=len(seg)-2**ind+i-1 ii len(seg)-2**ind+i-1 len(seg)-2**ind+i len(seg)-2**ind len(seg) len seg 2**ind 2 ind i 1 seg[ii]=2**(ord(s)-97) seg[ii] seg ii 2**(ord(s)-97) 2 ord(s)-97 ord(s) ord s 97 p=(ii-1)//2 p (ii-1)//2 ii-1 ii 1 2 while 1:
        seg[p]=seg[2*p+1]|seg[2*p+2]
        if p==0:
            break
        p=(p-1)//2

    #print(seg) 1 seg[p]=seg[2*p+1]|seg[2*p+2] seg[p] seg p seg[2*p+1]|seg[2*p+2] seg[2*p+1] seg 2*p+1 2*p 2 p 1 seg[2*p+2] seg 2*p+2 2*p 2 p 2 if p==0:
            break
         p==0 p 0 break p=(p-1)//2 p (p-1)//2 p-1 p 1 2 i i s s from collections import deque def count(l,r):
    global n,seg,s
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2

    d = deque([(1,len(s),0)])
    ans=0

    while len(d)>0:
        tmp=d.popleft()
        #print(tmp)
        ll,rr,i=tmp[0],tmp[1],tmp[2]
        if l<=ll and rr<=r:
            ans=ans|seg[i]
        elif (ll<=l and l<=rr) or (ll<=r and r<=rr):
            d.append((ll,ll+(rr-ll)//2,2*i+1))
            d.append((ll+(rr-ll)//2+1,rr,2*i+2))

    return str(bin(ans)).count("1") count global n,seg,s d = deque([(1,len(s),0)]) d deque([(1,len(s),0)]) deque [(1,len(s),0)] (1,len(s),0) 1 len(s) len s 0 ans=0 ans 0 while len(d)>0:
        tmp=d.popleft()
        #print(tmp)
        ll,rr,i=tmp[0],tmp[1],tmp[2]
        if l<=ll and rr<=r:
            ans=ans|seg[i]
        elif (ll<=l and l<=rr) or (ll<=r and r<=rr):
            d.append((ll,ll+(rr-ll)//2,2*i+1))
            d.append((ll+(rr-ll)//2+1,rr,2*i+2))

     len(d)>0 len(d) len d 0 tmp=d.popleft() tmp d.popleft() d.popleft d popleft ll,rr,i=tmp[0],tmp[1],tmp[2] ll tmp[0] tmp 0 rr tmp[1] tmp 1 i tmp[2] tmp 2 if l<=ll and rr<=r:
            ans=ans|seg[i]
        elif (ll<=l and l<=rr) or (ll<=r and r<=rr):
            d.append((ll,ll+(rr-ll)//2,2*i+1))
            d.append((ll+(rr-ll)//2+1,rr,2*i+2))

     l<=ll and rr<=r l<=ll l ll rr<=r rr r ans=ans|seg[i] ans ans|seg[i] ans seg[i] seg i elif (ll<=l and l<=rr) or (ll<=r and r<=rr):
            d.append((ll,ll+(rr-ll)//2,2*i+1))
            d.append((ll+(rr-ll)//2+1,rr,2*i+2))

     (ll<=l and l<=rr) or (ll<=r and r<=rr) ll<=l and l<=rr ll<=l ll l l<=rr l rr ll<=r and r<=rr ll<=r ll r r<=rr r rr d.append((ll,ll+(rr-ll)//2,2*i+1)) d.append d append (ll,ll+(rr-ll)//2,2*i+1) ll ll+(rr-ll)//2 ll (rr-ll)//2 rr-ll rr ll 2 2*i+1 2*i 2 i 1 d.append((ll+(rr-ll)//2+1,rr,2*i+2)) d.append d append (ll+(rr-ll)//2+1,rr,2*i+2) ll+(rr-ll)//2+1 ll+(rr-ll)//2 ll (rr-ll)//2 rr-ll rr ll 2 1 rr 2*i+2 2*i 2 i 2 return str(bin(ans)).count("1") str(bin(ans)).count("1") (bin(ans)).count (bin(ans)) str bin(ans) bin ans count "1" l l r r result=[] result [] for _ in range(q):
    b,i,c=map(str,input().split())
    if b=="1":
        #i文字目をcに変更
        change(int(i),c)
    else:
        #l文字目からr文字目までに含まれる数
        result.append(count(int(i),int(c))) _ range(q) range q b,i,c=map(str,input().split()) b map(str,input().split()) map str input().split() ().split () input split i c if b=="1":
        #i文字目をcに変更
        change(int(i),c)
    else:
        #l文字目からr文字目までに含まれる数
        result.append(count(int(i),int(c))) b=="1" b "1" change(int(i),c) change int(i) int i c result.append(count(int(i),int(c))) result.append result append count(int(i),int(c)) count int(i) int i int(c) int c for item in result:
    print(item)










    
          item result print(item) print item ind=1 1 ind t=tmp.popleft() tmp.popleft() t s=input() input() s ind+=1 1 ind tmp=deque([s]) deque([s]) tmp cnt=cnt|2**(ord(ss)-97) cnt|2**(ord(ss)-97) cnt q=int(input()) int(input()) q i,c=map(str,input().split()) map(str,input().split()) i n=int(input()) int(input()) n s+="*"*(2**ind-n) "*"*(2**ind-n) s b,i,c=map(str,input().split()) map(str,input().split()) b c=map(str,input().split()) map(str,input().split()) c cnt=0 0 cnt seg2=[] [] seg2 def change(i,s):
    #i文字目をsに変更する
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2
    global n,seg,ind
    ii=len(seg)-2**ind+i-1
    seg[ii]=2**(ord(s)-97)
    p=(ii-1)//2
    while 1:
        seg[p]=seg[2*p+1]|seg[2*p+2]
        if p==0:
            break
        p=(p-1)//2

    #print(seg) def change(i,s):
    #i文字目をsに変更する
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2
    global n,seg,ind
    ii=len(seg)-2**ind+i-1
    seg[ii]=2**(ord(s)-97)
    p=(ii-1)//2
    while 1:
        seg[p]=seg[2*p+1]|seg[2*p+2]
        if p==0:
            break
        p=(p-1)//2

    #print(seg) change def count(l,r):
    global n,seg,s
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2

    d = deque([(1,len(s),0)])
    ans=0

    while len(d)>0:
        tmp=d.popleft()
        #print(tmp)
        ll,rr,i=tmp[0],tmp[1],tmp[2]
        if l<=ll and rr<=r:
            ans=ans|seg[i]
        elif (ll<=l and l<=rr) or (ll<=r and r<=rr):
            d.append((ll,ll+(rr-ll)//2,2*i+1))
            d.append((ll+(rr-ll)//2+1,rr,2*i+2))

    return str(bin(ans)).count("1") def count(l,r):
    global n,seg,s
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2

    d = deque([(1,len(s),0)])
    ans=0

    while len(d)>0:
        tmp=d.popleft()
        #print(tmp)
        ll,rr,i=tmp[0],tmp[1],tmp[2]
        if l<=ll and rr<=r:
            ans=ans|seg[i]
        elif (ll<=l and l<=rr) or (ll<=r and r<=rr):
            d.append((ll,ll+(rr-ll)//2,2*i+1))
            d.append((ll+(rr-ll)//2+1,rr,2*i+2))

    return str(bin(ans)).count("1") count result=[] [] result seg=[] [] seg

n=int(input())
s=input()

#初期化
ind=1
while 2**ind<=n:
    ind+=1
s+="*"*(2**ind-n)
seg=[]
seg2=[]

from collections import deque
tmp=deque([s])
while len(tmp)>0:
    t=tmp.popleft()
    cnt=0
    for ss in t:
        if ss!="*":
            cnt=cnt|2**(ord(ss)-97)
    seg.append(cnt)
    seg2.append(t)
    if len(t)>1:
        tmp.append(t[:len(t)//2])
        tmp.append(t[len(t)//2:])

#セグ木が出来た！
#print(seg)
#print(seg2)

q=int(input())

def change(i,s):
    #i文字目をsに変更する
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2
    global n,seg,ind
    ii=len(seg)-2**ind+i-1
    seg[ii]=2**(ord(s)-97)
    p=(ii-1)//2
    while 1:
        seg[p]=seg[2*p+1]|seg[2*p+2]
        if p==0:
            break
        p=(p-1)//2

    #print(seg)

from collections import deque


def count(l,r):
    global n,seg,s
    #nの親は(n-1)//2
    #nの子は2n+1,2n+2

    d = deque([(1,len(s),0)])
    ans=0

    while len(d)>0:
        tmp=d.popleft()
        #print(tmp)
        ll,rr,i=tmp[0],tmp[1],tmp[2]
        if l<=ll and rr<=r:
            ans=ans|seg[i]
        elif (ll<=l and l<=rr) or (ll<=r and r<=rr):
            d.append((ll,ll+(rr-ll)//2,2*i+1))
            d.append((ll+(rr-ll)//2+1,rr,2*i+2))

    return str(bin(ans)).count("1")


result=[]


for _ in range(q):
    b,i,c=map(str,input().split())
    if b=="1":
        #i文字目をcに変更
        change(int(i),c)
    else:
        #l文字目からr文字目までに含まれる数
        result.append(count(int(i),int(c)))

for item in result:
    print(item)










    
         
