import sys
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))

# rstrip().decode('utf-8')

class BinaryIndexedTree:
	def __init__(self,n,default=0):
		self.s=[default]*(n+1)
		self.n=n
	
	def add(self,val,idx):
		while idx<self.n+1:
			self.s[idx]=self.s[idx]+val
			idx+=idx&(-idx)
		return
	
	def get(self,idx):
		res=0
		while idx>0:
			res=res+self.s[idx]
			idx-=idx&(-idx)
		return res

from collections import defaultdict

def main():
	n=II()
	s=input()
	S=[0]+list(s)
	
	d=defaultdict(lambda:BinaryIndexedTree(n))
	
	for i,si in enumerate(s):
		#print(i,si)
		d[si].add(1,i+1)
	
	q=II()
	for _ in range(q):
		f,a,b=input().split()
		if int(f)==1:
			a=int(a)
			d[S[a]].add(-1,a)
			d[b].add(1,a)
			S[a]=b
		else:
			#print(S,a,b)
			a=int(a)
			b=int(b)
			cnt=0
			for bit in d.values():
				if bit.get(b)-bit.get(a-1)>0:
					cnt+=1
			print(cnt)
		
	

if __name__=="__main__":
	main() import sys sys def RD(): return sys.stdin.read() RD def II(): return int(input()) II def MI(): return map(int,input().split()) MI def MF(): return map(float,input().split()) MF def LI(): return list(map(int,input().split())) LI def LF(): return list(map(float,input().split())) LF def TI(): return tuple(map(int,input().split()))

# rstrip().decode('utf-8') TI class BinaryIndexedTree:
	def __init__(self,n,default=0):
		self.s=[default]*(n+1)
		self.n=n
	
	def add(self,val,idx):
		while idx<self.n+1:
			self.s[idx]=self.s[idx]+val
			idx+=idx&(-idx)
		return
	
	def get(self,idx):
		res=0
		while idx>0:
			res=res+self.s[idx]
			idx-=idx&(-idx)
		return res BinaryIndexedTree def __init__(self,n,default=0):
		self.s=[default]*(n+1)
		self.n=n
	
	 __init__ self.s=[default]*(n+1) self.s self s [default]*(n+1) [default] default n+1 n 1 self.n=n self.n self n n self self n n default=0 default 0 def add(self,val,idx):
		while idx<self.n+1:
			self.s[idx]=self.s[idx]+val
			idx+=idx&(-idx)
		return
	
	 add while idx<self.n+1:
			self.s[idx]=self.s[idx]+val
			idx+=idx&(-idx)
		 idx<self.n+1 idx self.n+1 self.n self n 1 self.s[idx]=self.s[idx]+val self.s[idx] self.s self s idx self.s[idx]+val self.s[idx] self.s self s idx val idx+=idx&(-idx) idx idx&(-idx) idx -idx idx return self self val val idx idx def get(self,idx):
		res=0
		while idx>0:
			res=res+self.s[idx]
			idx-=idx&(-idx)
		return res get res=0 res 0 while idx>0:
			res=res+self.s[idx]
			idx-=idx&(-idx)
		 idx>0 idx 0 res=res+self.s[idx] res res+self.s[idx] res self.s[idx] self.s self s idx idx-=idx&(-idx) idx idx&(-idx) idx -idx idx return res res self self idx idx from collections import defaultdict def main():
	n=II()
	s=input()
	S=[0]+list(s)
	
	d=defaultdict(lambda:BinaryIndexedTree(n))
	
	for i,si in enumerate(s):
		#print(i,si)
		d[si].add(1,i+1)
	
	q=II()
	for _ in range(q):
		f,a,b=input().split()
		if int(f)==1:
			a=int(a)
			d[S[a]].add(-1,a)
			d[b].add(1,a)
			S[a]=b
		else:
			#print(S,a,b)
			a=int(a)
			b=int(b)
			cnt=0
			for bit in d.values():
				if bit.get(b)-bit.get(a-1)>0:
					cnt+=1
			print(cnt)
		
	 main n=II() n II() II s=input() s input() input S=[0]+list(s) S [0]+list(s) [0] 0 list(s) list s d=defaultdict(lambda:BinaryIndexedTree(n)) d defaultdict(lambda:BinaryIndexedTree(n)) defaultdict lambda:BinaryIndexedTree(n) BinaryIndexedTree(n) BinaryIndexedTree n for i,si in enumerate(s):
		#print(i,si)
		d[si].add(1,i+1)
	
	 i si enumerate(s) enumerate s d[si].add(1,i+1) [si].add [si] d si add 1 i+1 i 1 q=II() q II() II for _ in range(q):
		f,a,b=input().split()
		if int(f)==1:
			a=int(a)
			d[S[a]].add(-1,a)
			d[b].add(1,a)
			S[a]=b
		else:
			#print(S,a,b)
			a=int(a)
			b=int(b)
			cnt=0
			for bit in d.values():
				if bit.get(b)-bit.get(a-1)>0:
					cnt+=1
			print(cnt)
		
	 _ range(q) range q f,a,b=input().split() f input().split() ().split () input split a b if int(f)==1:
			a=int(a)
			d[S[a]].add(-1,a)
			d[b].add(1,a)
			S[a]=b
		else:
			#print(S,a,b)
			a=int(a)
			b=int(b)
			cnt=0
			for bit in d.values():
				if bit.get(b)-bit.get(a-1)>0:
					cnt+=1
			print(cnt)
		
	 int(f)==1 int(f) int f 1 a=int(a) a int(a) int a d[S[a]].add(-1,a) [S[a]].add [S[a]] d S[a] S a add -1 a d[b].add(1,a) [b].add [b] d b add 1 a S[a]=b S[a] S a b a=int(a) a int(a) int a b=int(b) b int(b) int b cnt=0 cnt 0 for bit in d.values():
				if bit.get(b)-bit.get(a-1)>0:
					cnt+=1
			 bit d.values() d.values d values if bit.get(b)-bit.get(a-1)>0:
					cnt+=1
			 bit.get(b)-bit.get(a-1)>0 bit.get(b)-bit.get(a-1) bit.get(b) bit.get bit get b bit.get(a-1) bit.get bit get a-1 a 1 0 cnt+=1 cnt 1 print(cnt) print cnt if __name__=="__main__":
	main() __name__=="__main__" __name__ "__main__" main() main def MI(): return map(int,input().split()) def MI(): return map(int,input().split()) MI def RD(): return sys.stdin.read() def RD(): return sys.stdin.read() RD def II(): return int(input()) def II(): return int(input()) II class BinaryIndexedTree:
	def __init__(self,n,default=0):
		self.s=[default]*(n+1)
		self.n=n
	
	def add(self,val,idx):
		while idx<self.n+1:
			self.s[idx]=self.s[idx]+val
			idx+=idx&(-idx)
		return
	
	def get(self,idx):
		res=0
		while idx>0:
			res=res+self.s[idx]
			idx-=idx&(-idx)
		return res class BinaryIndexedTree:
	def __init__(self,n,default=0):
		self.s=[default]*(n+1)
		self.n=n
	
	def add(self,val,idx):
		while idx<self.n+1:
			self.s[idx]=self.s[idx]+val
			idx+=idx&(-idx)
		return
	
	def get(self,idx):
		res=0
		while idx>0:
			res=res+self.s[idx]
			idx-=idx&(-idx)
		return res BinaryIndexedTree def LF(): return list(map(float,input().split())) def LF(): return list(map(float,input().split())) LF def MF(): return map(float,input().split()) def MF(): return map(float,input().split()) MF def TI(): return tuple(map(int,input().split()))

# rstrip().decode('utf-8') def TI(): return tuple(map(int,input().split()))

# rstrip().decode('utf-8') TI def LI(): return list(map(int,input().split())) def LI(): return list(map(int,input().split())) LI def main():
	n=II()
	s=input()
	S=[0]+list(s)
	
	d=defaultdict(lambda:BinaryIndexedTree(n))
	
	for i,si in enumerate(s):
		#print(i,si)
		d[si].add(1,i+1)
	
	q=II()
	for _ in range(q):
		f,a,b=input().split()
		if int(f)==1:
			a=int(a)
			d[S[a]].add(-1,a)
			d[b].add(1,a)
			S[a]=b
		else:
			#print(S,a,b)
			a=int(a)
			b=int(b)
			cnt=0
			for bit in d.values():
				if bit.get(b)-bit.get(a-1)>0:
					cnt+=1
			print(cnt)
		
	 def main():
	n=II()
	s=input()
	S=[0]+list(s)
	
	d=defaultdict(lambda:BinaryIndexedTree(n))
	
	for i,si in enumerate(s):
		#print(i,si)
		d[si].add(1,i+1)
	
	q=II()
	for _ in range(q):
		f,a,b=input().split()
		if int(f)==1:
			a=int(a)
			d[S[a]].add(-1,a)
			d[b].add(1,a)
			S[a]=b
		else:
			#print(S,a,b)
			a=int(a)
			b=int(b)
			cnt=0
			for bit in d.values():
				if bit.get(b)-bit.get(a-1)>0:
					cnt+=1
			print(cnt)
		
	 main
import sys
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))

# rstrip().decode('utf-8')

class BinaryIndexedTree:
	def __init__(self,n,default=0):
		self.s=[default]*(n+1)
		self.n=n
	
	def add(self,val,idx):
		while idx<self.n+1:
			self.s[idx]=self.s[idx]+val
			idx+=idx&(-idx)
		return
	
	def get(self,idx):
		res=0
		while idx>0:
			res=res+self.s[idx]
			idx-=idx&(-idx)
		return res

from collections import defaultdict

def main():
	n=II()
	s=input()
	S=[0]+list(s)
	
	d=defaultdict(lambda:BinaryIndexedTree(n))
	
	for i,si in enumerate(s):
		#print(i,si)
		d[si].add(1,i+1)
	
	q=II()
	for _ in range(q):
		f,a,b=input().split()
		if int(f)==1:
			a=int(a)
			d[S[a]].add(-1,a)
			d[b].add(1,a)
			S[a]=b
		else:
			#print(S,a,b)
			a=int(a)
			b=int(b)
			cnt=0
			for bit in d.values():
				if bit.get(b)-bit.get(a-1)>0:
					cnt+=1
			print(cnt)
		
	

if __name__=="__main__":
	main()
