/*
_____________________$$o____________________o$$$$$o__
___________________o$o_$$o____oo$$$$$$$oo______o$$$$o
______________$o________o$$$$$o___oo$$$$$$$o______$$$
______________$$$ooo________o$$$$o______o$$$$$o_____o
____________oo_____oo_____oo___o$$$$$______$$$$$$____
_________ooooo___$$o_$___oooooo___o$$$$o__o__o$$$$___
_______ooo__ooo$$$$o_$$ooooooooooo__o$$$o__oo_oo$$$o_
______oo_o$$o_$$_o$o_o$o__oooooooooo__o$$$o_oo__o$$$o
____oooooo$$$$o___oo__$$o_ooo_oooooooo__o$$o_ooo_o$$$
___ooooooo__o___oooo__$$ooooo$_oooooooo__o$$__ooo_$$$
_$$o_ooooo___o$$$$$o__o$o__o_$o__oooooooo_o$$o_oo__$$
_$$$o_ooo_________o$$_$$o____$$o_ooooooooo_$$$o_oo_$$
__oo________o$$o____o_$$o____o$ooooooooooo_o$$o_oo_o$
___o$$$$$$$$$$$$$o___$$$o____$$o_oooooooooo_$$$o_o_o$
________o__oo$$$$$o__$$$o____$$o____oooooo__$$$o_o_o$
_________$$$$$$$$$o__$$_____$$$o___________$$$oooooo_
__________o$$$$$$$o_________$$___________o$o___oooooo
___________o$$$$o_______________ooooo__oo$__ooo__oooo
________________________________ooo_$$oo___oooo$o____
________________________________oooo_$$$$$o___oo$$$o_
________________________________ooooo_o$$$$$o_____$$$
________________________________oooooo_o$$$$$$ooo___o
________________________________ooooooo__o$$$$$o_____
*/
#include<bits/stdc++.h>
#define ll long long
#define ft first
#define sd second
#define HageBaIO_KPOCCbI int LOL;scanf("%d", &LOL);for(int i = 0; i < LOL; i++)
#define Terrorist ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
//BY |3 |<
const int dx[] = {1, 0, -1,  0};
const int dy[] = {0, 1,  0, -1};
//Where I am?
const ll N = 5e5 + 5;
const ll NN = 3e3 + 3;
const ll MOD = (1e9 + 7);
const ll MOD1 = 998244353;
const double PI = 3.14159265;
const int INF32 = 2e9;
const ll INF64 = 2e18;
//Don`t believe!!!//
int n, q;
bool arr[26][N], t[26][(N << 2)];
string s;
void build(int v = 1, int tl = 1, int tr = n){
	if(tl == tr){
		for(int i = 0; i < 26; i++){
			t[i][v] = arr[i][tl];
		}
	}
	else{
		int tm = ((tl + tr) >> 1);
		build((v << 1), tl, tm);
		build((v << 1) + 1, tm + 1, tr);
		for(int i = 0; i < 26; i++){
			t[i][v] = (t[i][(v << 1)] | t[i][(v << 1) + 1]);
		}
	}
}
void update(int ch, int gg, int pos, int v = 1, int tl = 1, int tr = n){
	if(tl == tr){
		t[ch][v] = 0;
		t[gg][v] = 1;
	}
	else{
		int tm = ((tl + tr) >> 1);
		if(pos <= tm)update(ch, gg, pos, (v << 1), tl, tm);
		else update(ch, gg, pos, (v << 1) + 1, tm + 1, tr);
		t[ch][v] = (t[ch][(v << 1)] | t[ch][(v << 1) + 1]);
		t[gg][v] = (t[gg][(v << 1)] | t[gg][(v << 1) + 1]);
	}
}
bool get(int l, int r, int gg, int v = 1, int tl = 1, int tr = n){
	if(tl > r || tr < l)return 0;
	if(l <= tl && tr <= r)return t[gg][v];
	int tm = ((tl + tr) >> 1);
	return (get(l, r, gg, (v << 1), tl, tm) || get(l, r, gg, (v << 1) + 1, tm + 1, tr));
}
void KEK(){
	cin>>n>>s>>q;
	for(int i = 0, c = 0; i < s.size(); i++){
		arr[(s[i] - 'a')][i + 1] = 1;
	}
	build();
	for(int i = 0, t, l, r; i < q; i++){
		cin>>t;
		if(t == 1){
			char ch;
			cin>>l>>ch;
			if(s[l - 1] != ch)update((s[l - 1] - 'a'), (ch - 'a'), l);
			s[l - 1] = ch;
		}
		else{
			cin>>l>>r;
			int ans = 0;
			for(int j = 0; j < 26; j++)ans += get(l, r, j);
			cout<<ans<<endl;
		}
	}
}
int main(){
	Terrorist
	//HageBaIO_KPOCCbI
	KEK();
	return 0;
}
//TAUMAC, 9| BbIWEJI 3A TObOU!!!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 63644