// E - Simple String Queries
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int N,Q;
string S;
vector<set<int>> abc(26);

void add(int i, char c){//type1
	if(S[i] == c) return;
	abc[S[i]-'a'].erase(i);
	S[i] = c;
	abc[S[i]-'a'].insert(i);
}

void out(int l, int r){//type2
	int ans = 0;
	rep(i,26){
		if(abc[i].size() <= 0) continue;
		auto it = abc[i].lower_bound(l);
		if(it == abc[i].end()) continue;
		if(*it <= r) ans++;
	}
	printf("%d\n",ans);
}

int main(){
	cin>>N>>S>>Q;
	rep(i,N) abc[S[i]-'a'].insert(i);
	rep(i,Q){
		int t,a;
		cin>>t;
		if(t-1){//type2
			int b;
			cin>>a>>b;
			out(a-1, b-1);
		}
		else{//type1
			char b;
			cin>>a>>b;
			add(a-1, b);
		}
	}
}