from bisect import bisect_left, bisect_right, insort_left

n = int(input())
s = list(input())
q = int(input())

d = {}
flag = {}
for i in list('abcdefghijklmnopqrstuvwxyz'):
	d.setdefault(i, []).append(-1)
	flag.setdefault(i, []).append(-1)
for i in range(n):
	d.setdefault(s[i], []).append(i)
for i in range(q):
	q1,q2,q3 = map(str,input().split())
	if q1 == '1':
		q2 = int(q2) - 1
		if s[q2] != q3:
			insort_left(flag[s[q2]],q2)
			insort_left(d[q3],q2)
			s[q2] = q3
	else:
		ans = 0
		q2 = int(q2) - 1
		q3 = int(q3) - 1
		if q2 == q3:
			print(1)
			continue
		for string,l in d.items():
			res = 0
			if d[string] != [-1]:
				left = bisect_left(l,q2)
				right = bisect_right(l,q3)
			else:
				left = 0
				right = 0
			if string in flag:
				left2 = bisect_left(flag[string],q2)
				right2 = bisect_right(flag[string],q3)
			else:
				left2 = 0
				right2 = 0
			if left != right:
				if right - left > right2 - left2:
					res = 1
			ans += res
			#print(string,l,res)
		print(ans) from bisect import bisect_left, bisect_right, insort_left 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 d = {} d {} flag = {} flag {} for i in list('abcdefghijklmnopqrstuvwxyz'):
	d.setdefault(i, []).append(-1)
	flag.setdefault(i, []).append(-1) i list('abcdefghijklmnopqrstuvwxyz') list 'abcdefghijklmnopqrstuvwxyz' d.setdefault(i, []).append(-1) d.setdefault(i, []).append d.setdefault(i, []) d.setdefault d setdefault i [] append -1 flag.setdefault(i, []).append(-1) flag.setdefault(i, []).append flag.setdefault(i, []) flag.setdefault flag setdefault i [] append -1 for i in range(n):
	d.setdefault(s[i], []).append(i) i range(n) range n d.setdefault(s[i], []).append(i) d.setdefault(s[i], []).append d.setdefault(s[i], []) d.setdefault d setdefault s[i] s i [] append i for i in range(q):
	q1,q2,q3 = map(str,input().split())
	if q1 == '1':
		q2 = int(q2) - 1
		if s[q2] != q3:
			insort_left(flag[s[q2]],q2)
			insort_left(d[q3],q2)
			s[q2] = q3
	else:
		ans = 0
		q2 = int(q2) - 1
		q3 = int(q3) - 1
		if q2 == q3:
			print(1)
			continue
		for string,l in d.items():
			res = 0
			if d[string] != [-1]:
				left = bisect_left(l,q2)
				right = bisect_right(l,q3)
			else:
				left = 0
				right = 0
			if string in flag:
				left2 = bisect_left(flag[string],q2)
				right2 = bisect_right(flag[string],q3)
			else:
				left2 = 0
				right2 = 0
			if left != right:
				if right - left > right2 - left2:
					res = 1
			ans += res
			#print(string,l,res)
		print(ans) i range(q) range q q1,q2,q3 = map(str,input().split()) q1 map(str,input().split()) map str input().split() ().split () input split q2 q3 if q1 == '1':
		q2 = int(q2) - 1
		if s[q2] != q3:
			insort_left(flag[s[q2]],q2)
			insort_left(d[q3],q2)
			s[q2] = q3
	else:
		ans = 0
		q2 = int(q2) - 1
		q3 = int(q3) - 1
		if q2 == q3:
			print(1)
			continue
		for string,l in d.items():
			res = 0
			if d[string] != [-1]:
				left = bisect_left(l,q2)
				right = bisect_right(l,q3)
			else:
				left = 0
				right = 0
			if string in flag:
				left2 = bisect_left(flag[string],q2)
				right2 = bisect_right(flag[string],q3)
			else:
				left2 = 0
				right2 = 0
			if left != right:
				if right - left > right2 - left2:
					res = 1
			ans += res
			#print(string,l,res)
		print(ans) q1 == '1' q1 '1' q2 = int(q2) - 1 q2 int(q2) - 1 int(q2) int q2 1 if s[q2] != q3:
			insort_left(flag[s[q2]],q2)
			insort_left(d[q3],q2)
			s[q2] = q3
	 s[q2] != q3 s[q2] s q2 q3 insort_left(flag[s[q2]],q2) insort_left flag[s[q2]] flag s[q2] s q2 q2 insort_left(d[q3],q2) insort_left d[q3] d q3 q2 s[q2] = q3 s[q2] s q2 q3 ans = 0 ans 0 q2 = int(q2) - 1 q2 int(q2) - 1 int(q2) int q2 1 q3 = int(q3) - 1 q3 int(q3) - 1 int(q3) int q3 1 if q2 == q3:
			print(1)
			continue
		 q2 == q3 q2 q3 print(1) print 1 continue for string,l in d.items():
			res = 0
			if d[string] != [-1]:
				left = bisect_left(l,q2)
				right = bisect_right(l,q3)
			else:
				left = 0
				right = 0
			if string in flag:
				left2 = bisect_left(flag[string],q2)
				right2 = bisect_right(flag[string],q3)
			else:
				left2 = 0
				right2 = 0
			if left != right:
				if right - left > right2 - left2:
					res = 1
			ans += res
			#print(string,l,res)
		 string l d.items() d.items d items res = 0 res 0 if d[string] != [-1]:
				left = bisect_left(l,q2)
				right = bisect_right(l,q3)
			else:
				left = 0
				right = 0
			 d[string] != [-1] d[string] d string [-1] -1 left = bisect_left(l,q2) left bisect_left(l,q2) bisect_left l q2 right = bisect_right(l,q3) right bisect_right(l,q3) bisect_right l q3 left = 0 left 0 right = 0 right 0 if string in flag:
				left2 = bisect_left(flag[string],q2)
				right2 = bisect_right(flag[string],q3)
			else:
				left2 = 0
				right2 = 0
			 string in flag string flag left2 = bisect_left(flag[string],q2) left2 bisect_left(flag[string],q2) bisect_left flag[string] flag string q2 right2 = bisect_right(flag[string],q3) right2 bisect_right(flag[string],q3) bisect_right flag[string] flag string q3 left2 = 0 left2 0 right2 = 0 right2 0 if left != right:
				if right - left > right2 - left2:
					res = 1
			 left != right left right if right - left > right2 - left2:
					res = 1
			 right - left > right2 - left2 right - left right left right2 - left2 right2 left2 res = 1 res 1 ans += res ans res print(ans) print ans q3 = int(q3) - 1 int(q3) - 1 q3 q1,q2,q3 = map(str,input().split()) map(str,input().split()) q1 s = list(input()) list(input()) s res = 1 1 res left2 = bisect_left(flag[string],q2) bisect_left(flag[string],q2) left2 left = bisect_left(l,q2) bisect_left(l,q2) left left2 = 0 0 left2 q2 = int(q2) - 1 int(q2) - 1 q2 q2,q3 = map(str,input().split()) map(str,input().split()) q2 q = int(input()) int(input()) q q2 = int(q2) - 1 int(q2) - 1 q2 right = bisect_right(l,q3) bisect_right(l,q3) right res = 0 0 res right2 = bisect_right(flag[string],q3) bisect_right(flag[string],q3) right2 right2 = 0 0 right2 q3 = map(str,input().split()) map(str,input().split()) q3 ans = 0 0 ans ans += res res ans n = int(input()) int(input()) n left = 0 0 left d = {} {} d flag = {} {} flag right = 0 0 right
from bisect import bisect_left, bisect_right, insort_left

n = int(input())
s = list(input())
q = int(input())

d = {}
flag = {}
for i in list('abcdefghijklmnopqrstuvwxyz'):
	d.setdefault(i, []).append(-1)
	flag.setdefault(i, []).append(-1)
for i in range(n):
	d.setdefault(s[i], []).append(i)
for i in range(q):
	q1,q2,q3 = map(str,input().split())
	if q1 == '1':
		q2 = int(q2) - 1
		if s[q2] != q3:
			insort_left(flag[s[q2]],q2)
			insort_left(d[q3],q2)
			s[q2] = q3
	else:
		ans = 0
		q2 = int(q2) - 1
		q3 = int(q3) - 1
		if q2 == q3:
			print(1)
			continue
		for string,l in d.items():
			res = 0
			if d[string] != [-1]:
				left = bisect_left(l,q2)
				right = bisect_right(l,q3)
			else:
				left = 0
				right = 0
			if string in flag:
				left2 = bisect_left(flag[string],q2)
				right2 = bisect_right(flag[string],q3)
			else:
				left2 = 0
				right2 = 0
			if left != right:
				if right - left > right2 - left2:
					res = 1
			ans += res
			#print(string,l,res)
		print(ans)
