#segtree ライブラリ
#BITライブラリの作成
#リストの要素を1,0で長さをｎとした時に使える
class BIT:
    def __init__(self,n):
        self.n=n
        self.data=[0]*(n+1)
    def to_sum(self,i):
        s=0     
        while i>0:
            s+=self.data[i]
            i-=(i& -i)
        return s
    def add(self,i,x):
        while i<=self.n:
            self.data[i]+=x
            i+=(i & -i)
    def get(self,i,j):
        return self.to_sum(j)-self.to_sum(i-1)
n=int(input())
s=list(input())
q=int(input())
que=[]

for i in range(q):
    p=list(input().split())
    que.append(p)
alpha="abcdefghijklmnopqrstuvwxyz"
segtree={alpha[i]:BIT(n) for i in range(26)}  
for i in range(n):
    segtree[s[i]].add(i+1,1)
for q in que:
    x,y,z=q[0],q[1],q[2]
    if int(x)==1:
        #y文字目をzに変更する
        y=int(y)  
        for i in range(26):
            if segtree[alpha[i]].get(y,y)==1:
                segtree[alpha[i]].add(y,-1)
                break
        segtree[z].add(y,1)
    else:
        ans=0
        for i in range(26):
            if segtree[alpha[i]].get(int(y),int(z))>0:
                ans+=1
        print(ans)        class BIT:
    def __init__(self,n):
        self.n=n
        self.data=[0]*(n+1)
    def to_sum(self,i):
        s=0     
        while i>0:
            s+=self.data[i]
            i-=(i& -i)
        return s
    def add(self,i,x):
        while i<=self.n:
            self.data[i]+=x
            i+=(i & -i)
    def get(self,i,j):
        return self.to_sum(j)-self.to_sum(i-1) BIT def __init__(self,n):
        self.n=n
        self.data=[0]*(n+1)
     __init__ self.n=n self.n self n n self.data=[0]*(n+1) self.data self data [0]*(n+1) [0] 0 n+1 n 1 self self n n def to_sum(self,i):
        s=0     
        while i>0:
            s+=self.data[i]
            i-=(i& -i)
        return s
     to_sum s=0 s 0 while i>0:
            s+=self.data[i]
            i-=(i& -i)
         i>0 i 0 s+=self.data[i] s self.data[i] self.data self data i i-=(i& -i) i i& -i i -i i return s s self self i i def add(self,i,x):
        while i<=self.n:
            self.data[i]+=x
            i+=(i & -i)
     add while i<=self.n:
            self.data[i]+=x
            i+=(i & -i)
     i<=self.n i self.n self n self.data[i]+=x self.data[i] self.data self data i x i+=(i & -i) i i & -i i -i i self self i i x x def get(self,i,j):
        return self.to_sum(j)-self.to_sum(i-1) get return self.to_sum(j)-self.to_sum(i-1) self.to_sum(j)-self.to_sum(i-1) self.to_sum(j) self.to_sum self to_sum j self.to_sum(i-1) self.to_sum self to_sum i-1 i 1 self self i i j j 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 que=[] que [] for i in range(q):
    p=list(input().split())
    que.append(p) i range(q) range q p=list(input().split()) p list(input().split()) list input().split() ().split () input split que.append(p) que.append que append p alpha="abcdefghijklmnopqrstuvwxyz" alpha "abcdefghijklmnopqrstuvwxyz" alpha[i]:BIT(n) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) alpha[i] alpha i BIT(n) BIT n segtree={alpha[i]:BIT(n) for i in range(26)} segtree {alpha[i]:BIT(n) for i in range(26)} for i in range(n):
    segtree[s[i]].add(i+1,1) i range(n) range n segtree[s[i]].add(i+1,1) [s[i]].add [s[i]] segtree s[i] s i add i+1 i 1 1 for q in que:
    x,y,z=q[0],q[1],q[2]
    if int(x)==1:
        #y文字目をzに変更する
        y=int(y)  
        for i in range(26):
            if segtree[alpha[i]].get(y,y)==1:
                segtree[alpha[i]].add(y,-1)
                break
        segtree[z].add(y,1)
    else:
        ans=0
        for i in range(26):
            if segtree[alpha[i]].get(int(y),int(z))>0:
                ans+=1
        print(ans)        q que x,y,z=q[0],q[1],q[2] x q[0] q 0 y q[1] q 1 z q[2] q 2 if int(x)==1:
        #y文字目をzに変更する
        y=int(y)  
        for i in range(26):
            if segtree[alpha[i]].get(y,y)==1:
                segtree[alpha[i]].add(y,-1)
                break
        segtree[z].add(y,1)
    else:
        ans=0
        for i in range(26):
            if segtree[alpha[i]].get(int(y),int(z))>0:
                ans+=1
        print(ans)        int(x)==1 int(x) int x 1 y=int(y) y int(y) int y for i in range(26):
            if segtree[alpha[i]].get(y,y)==1:
                segtree[alpha[i]].add(y,-1)
                break
         i range(26) range 26 if segtree[alpha[i]].get(y,y)==1:
                segtree[alpha[i]].add(y,-1)
                break
         segtree[alpha[i]].get(y,y)==1 segtree[alpha[i]].get(y,y) [alpha[i]].get [alpha[i]] segtree alpha[i] alpha i get y y 1 segtree[alpha[i]].add(y,-1) [alpha[i]].add [alpha[i]] segtree alpha[i] alpha i add y -1 break segtree[z].add(y,1) [z].add [z] segtree z add y 1 ans=0 ans 0 for i in range(26):
            if segtree[alpha[i]].get(int(y),int(z))>0:
                ans+=1
         i range(26) range 26 if segtree[alpha[i]].get(int(y),int(z))>0:
                ans+=1
         segtree[alpha[i]].get(int(y),int(z))>0 segtree[alpha[i]].get(int(y),int(z)) [alpha[i]].get [alpha[i]] segtree alpha[i] alpha i get int(y) int y int(z) int z 0 ans+=1 ans 1 print(ans) print ans y,z=q[0],q[1],q[2] q[1] y class BIT:
    def __init__(self,n):
        self.n=n
        self.data=[0]*(n+1)
    def to_sum(self,i):
        s=0     
        while i>0:
            s+=self.data[i]
            i-=(i& -i)
        return s
    def add(self,i,x):
        while i<=self.n:
            self.data[i]+=x
            i+=(i & -i)
    def get(self,i,j):
        return self.to_sum(j)-self.to_sum(i-1) class BIT:
    def __init__(self,n):
        self.n=n
        self.data=[0]*(n+1)
    def to_sum(self,i):
        s=0     
        while i>0:
            s+=self.data[i]
            i-=(i& -i)
        return s
    def add(self,i,x):
        while i<=self.n:
            self.data[i]+=x
            i+=(i & -i)
    def get(self,i,j):
        return self.to_sum(j)-self.to_sum(i-1) BIT x,y,z=q[0],q[1],q[2] q[0] x p=list(input().split()) list(input().split()) p alpha="abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alpha que=[] [] que segtree={alpha[i]:BIT(n) for i in range(26)} {alpha[i]:BIT(n) for i in range(26)} segtree ans=0 0 ans q=int(input()) int(input()) q y=int(y) int(y) y z=q[0],q[1],q[2] q[2] z n=int(input()) int(input()) n s=list(input()) list(input()) s ans+=1 1 ans
#segtree ライブラリ
#BITライブラリの作成
#リストの要素を1,0で長さをｎとした時に使える
class BIT:
    def __init__(self,n):
        self.n=n
        self.data=[0]*(n+1)
    def to_sum(self,i):
        s=0     
        while i>0:
            s+=self.data[i]
            i-=(i& -i)
        return s
    def add(self,i,x):
        while i<=self.n:
            self.data[i]+=x
            i+=(i & -i)
    def get(self,i,j):
        return self.to_sum(j)-self.to_sum(i-1)
n=int(input())
s=list(input())
q=int(input())
que=[]

for i in range(q):
    p=list(input().split())
    que.append(p)
alpha="abcdefghijklmnopqrstuvwxyz"
segtree={alpha[i]:BIT(n) for i in range(26)}  
for i in range(n):
    segtree[s[i]].add(i+1,1)
for q in que:
    x,y,z=q[0],q[1],q[2]
    if int(x)==1:
        #y文字目をzに変更する
        y=int(y)  
        for i in range(26):
            if segtree[alpha[i]].get(y,y)==1:
                segtree[alpha[i]].add(y,-1)
                break
        segtree[z].add(y,1)
    else:
        ans=0
        for i in range(26):
            if segtree[alpha[i]].get(int(y),int(z))>0:
                ans+=1
        print(ans)       
