#ABC157E

n = int(input())
s = list(input())
q = int(input())
bits = [[0 for _ in range(n+1)] for _ in range(26)]
sl = []
for alp in s:
	alpord = ord(alp) - 97
	sl.append(alpord)
#print(bits) #test
#print(sl) #test
#print('クエリ開始') #test

def query(pos):
	ret = [0] * 26
	p = pos
	while p > 0:
		for i in range(26):
			ret[i] += bits[i][p]
		p -= p&(-p)
	return ret

def update(pos, a, x):
	r = pos
	while r <= n:
		bits[a][r] += x
		r += r&(-r)

for i in range(n):
	update(i+1, sl[i], 1)
#print(bits) #test

for _ in range(q):
	quer, xx, yy = map(str, input().split())
	if quer == '1':
		x = int(xx)
		y = ord(yy) - 97
		if sl[x-1] == y:
			continue
		else:
			update(x, sl[x-1], -1)
			update(x, y, 1)
			sl[x-1] = y
		#print('クエリ1でした') #test
		#print(bits) #test
		#print(sl) #test
	else:
		x = int(xx)
		y = int(yy)
		cnt1 = query(y)
		cnt2 = query(x-1)
		#print('クエリ2です') #test
		#print(cnt1) #test
		#print(cnt2) #test
		ans = 0
		for i in range(26):
			if cnt1[i] - cnt2[i] > 0:
				ans += 1
		print(ans) 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 [0 for _ in range(n+1)] for _ in range(26) for _ in range(26) _ range(26) range 26 for _ in range(26) [0 for _ in range(n+1)] bits = [[0 for _ in range(n+1)] for _ in range(26)] bits [[0 for _ in range(n+1)] for _ in range(26)] sl = [] sl [] for alp in s:
	alpord = ord(alp) - 97
	sl.append(alpord)
#print(bits) #test
#print(sl) #test
#print('クエリ開始') #test alp s alpord = ord(alp) - 97 alpord ord(alp) - 97 ord(alp) ord alp 97 sl.append(alpord) sl.append sl append alpord def query(pos):
	ret = [0] * 26
	p = pos
	while p > 0:
		for i in range(26):
			ret[i] += bits[i][p]
		p -= p&(-p)
	return ret query ret = [0] * 26 ret [0] * 26 [0] 0 26 p = pos p pos while p > 0:
		for i in range(26):
			ret[i] += bits[i][p]
		p -= p&(-p)
	 p > 0 p 0 for i in range(26):
			ret[i] += bits[i][p]
		 i range(26) range 26 ret[i] += bits[i][p] ret[i] ret i bits[i][p] [i] bits i p p -= p&(-p) p p&(-p) p -p p return ret ret pos pos def update(pos, a, x):
	r = pos
	while r <= n:
		bits[a][r] += x
		r += r&(-r) update r = pos r pos while r <= n:
		bits[a][r] += x
		r += r&(-r) r <= n r n bits[a][r] += x bits[a][r] [a] bits a r x r += r&(-r) r r&(-r) r -r r pos pos a a x x for i in range(n):
	update(i+1, sl[i], 1)
#print(bits) #test i range(n) range n update(i+1, sl[i], 1) update i+1 i 1 sl[i] sl i 1 for _ in range(q):
	quer, xx, yy = map(str, input().split())
	if quer == '1':
		x = int(xx)
		y = ord(yy) - 97
		if sl[x-1] == y:
			continue
		else:
			update(x, sl[x-1], -1)
			update(x, y, 1)
			sl[x-1] = y
		#print('クエリ1でした') #test
		#print(bits) #test
		#print(sl) #test
	else:
		x = int(xx)
		y = int(yy)
		cnt1 = query(y)
		cnt2 = query(x-1)
		#print('クエリ2です') #test
		#print(cnt1) #test
		#print(cnt2) #test
		ans = 0
		for i in range(26):
			if cnt1[i] - cnt2[i] > 0:
				ans += 1
		print(ans) _ range(q) range q quer, xx, yy = map(str, input().split()) quer map(str, input().split()) map str input().split() ().split () input split xx yy if quer == '1':
		x = int(xx)
		y = ord(yy) - 97
		if sl[x-1] == y:
			continue
		else:
			update(x, sl[x-1], -1)
			update(x, y, 1)
			sl[x-1] = y
		#print('クエリ1でした') #test
		#print(bits) #test
		#print(sl) #test
	else:
		x = int(xx)
		y = int(yy)
		cnt1 = query(y)
		cnt2 = query(x-1)
		#print('クエリ2です') #test
		#print(cnt1) #test
		#print(cnt2) #test
		ans = 0
		for i in range(26):
			if cnt1[i] - cnt2[i] > 0:
				ans += 1
		print(ans) quer == '1' quer '1' x = int(xx) x int(xx) int xx y = ord(yy) - 97 y ord(yy) - 97 ord(yy) ord yy 97 if sl[x-1] == y:
			continue
		else:
			update(x, sl[x-1], -1)
			update(x, y, 1)
			sl[x-1] = y
		#print('クエリ1でした') #test
		#print(bits) #test
		#print(sl) #test
	 sl[x-1] == y sl[x-1] sl x-1 x 1 y continue update(x, sl[x-1], -1) update x sl[x-1] sl x-1 x 1 -1 update(x, y, 1) update x y 1 sl[x-1] = y sl[x-1] sl x-1 x 1 y x = int(xx) x int(xx) int xx y = int(yy) y int(yy) int yy cnt1 = query(y) cnt1 query(y) query y cnt2 = query(x-1) cnt2 query(x-1) query x-1 x 1 ans = 0 ans 0 for i in range(26):
			if cnt1[i] - cnt2[i] > 0:
				ans += 1
		 i range(26) range 26 if cnt1[i] - cnt2[i] > 0:
				ans += 1
		 cnt1[i] - cnt2[i] > 0 cnt1[i] - cnt2[i] cnt1[i] cnt1 i cnt2[i] cnt2 i 0 ans += 1 ans 1 print(ans) print ans def query(pos):
	ret = [0] * 26
	p = pos
	while p > 0:
		for i in range(26):
			ret[i] += bits[i][p]
		p -= p&(-p)
	return ret def query(pos):
	ret = [0] * 26
	p = pos
	while p > 0:
		for i in range(26):
			ret[i] += bits[i][p]
		p -= p&(-p)
	return ret query cnt1 = query(y) query(y) cnt1 bits = [[0 for _ in range(n+1)] for _ in range(26)] [[0 for _ in range(n+1)] for _ in range(26)] bits x = int(xx) int(xx) x y = int(yy) int(yy) y alpord = ord(alp) - 97 ord(alp) - 97 alpord quer, xx, yy = map(str, input().split()) map(str, input().split()) quer ans += 1 1 ans s = list(input()) list(input()) s sl = [] [] sl q = int(input()) int(input()) q def update(pos, a, x):
	r = pos
	while r <= n:
		bits[a][r] += x
		r += r&(-r) def update(pos, a, x):
	r = pos
	while r <= n:
		bits[a][r] += x
		r += r&(-r) update yy = map(str, input().split()) map(str, input().split()) yy y = ord(yy) - 97 ord(yy) - 97 y n = int(input()) int(input()) n cnt2 = query(x-1) query(x-1) cnt2 xx, yy = map(str, input().split()) map(str, input().split()) xx x = int(xx) int(xx) x ans = 0 0 ans
#ABC157E

n = int(input())
s = list(input())
q = int(input())
bits = [[0 for _ in range(n+1)] for _ in range(26)]
sl = []
for alp in s:
	alpord = ord(alp) - 97
	sl.append(alpord)
#print(bits) #test
#print(sl) #test
#print('クエリ開始') #test

def query(pos):
	ret = [0] * 26
	p = pos
	while p > 0:
		for i in range(26):
			ret[i] += bits[i][p]
		p -= p&(-p)
	return ret

def update(pos, a, x):
	r = pos
	while r <= n:
		bits[a][r] += x
		r += r&(-r)

for i in range(n):
	update(i+1, sl[i], 1)
#print(bits) #test

for _ in range(q):
	quer, xx, yy = map(str, input().split())
	if quer == '1':
		x = int(xx)
		y = ord(yy) - 97
		if sl[x-1] == y:
			continue
		else:
			update(x, sl[x-1], -1)
			update(x, y, 1)
			sl[x-1] = y
		#print('クエリ1でした') #test
		#print(bits) #test
		#print(sl) #test
	else:
		x = int(xx)
		y = int(yy)
		cnt1 = query(y)
		cnt2 = query(x-1)
		#print('クエリ2です') #test
		#print(cnt1) #test
		#print(cnt2) #test
		ans = 0
		for i in range(26):
			if cnt1[i] - cnt2[i] > 0:
				ans += 1
		print(ans)