#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
class RangeQuery{
public:
	virtual T CalculateCost(T left,T right)=0;
	virtual void EvaluateElement(T& left,T right)=0;
	virtual void EvaluateLazy(T& left,T right)=0;
	virtual void UpdateLazy(T& left,T right,T vleft,T vright)=0;
};

template<typename T>
class RangeAddQuery:public RangeQuery<T>{
public:
	T CalculateCost(T left,T right){return left+right;}
	void EvaluateElement(T& left,T right){left+=right;}
	void EvaluateLazy(T& left,T right){left+=right/2;}
	void UpdateLazy(T& left,T right,T vleft,T vright){left+=(vright-vleft)*right;}
};

template<typename T>
class SegmentTree{
	T def_value;
	int last_num;
	vector<T> element,lazy;
	vector<bool> lazy_flag;
	unique_ptr<RangeQuery<T>> range_query;
public:
	SegmentTree(){}
	void Construct(vector<T>& vec,T def){
		def_value=def;
		int N=vec.size();
		last_num=1;
		while(last_num<N) last_num <<= 1;
		element.resize(2*last_num-1,def);
		lazy.resize(2*last_num-1,0);
		lazy_flag.resize(2*last_num-1,false);

		range_query = make_unique<RangeAddQuery<T>>();

		for(int i=0;i<N;i++){
			element[i+last_num-1] = vec[i];
		}
		for(int i=last_num-2;i>=0;i--){
			element[i] = range_query->CalculateCost(element[2*i+1],element[2*i+2]);
		}
	}
	SegmentTree(vector<T>& vec,T def):def_value(def){
		int N=vec.size();
		last_num=1;
		while(last_num<N) last_num <<= 1;
		element.resize(2*last_num-1,def);
		lazy.resize(2*last_num-1,0);
		lazy_flag.resize(2*last_num-1,false);

		range_query = make_unique<RangeAddQuery<T>>();

		for(int i=0;i<N;i++){
			element[i+last_num-1] = vec[i];
		}
		for(int i=last_num-2;i>=0;i--){
			element[i] = range_query->CalculateCost(element[2*i+1],element[2*i+2]);
		}
	}
	void Evaluate(int index,int left,int right){
		if(!lazy_flag[index]) return;
		range_query->EvaluateElement(element[index],lazy[index]);
		if(right-left>1){
			range_query->EvaluateLazy(lazy[2*index+1],lazy[index]);
			range_query->EvaluateLazy(lazy[2*index+2],lazy[index]);
			lazy_flag[2*index+1] = lazy_flag[2*index+2] = true;
		}
		lazy[index] = 0;
		lazy_flag[index] = false;
	}
	void UpdateRange(int left,int right,T x,int index=0,int vleft=0,int vright=-1){
		if(vright<0) vright = last_num;
		Evaluate(index,vleft,vright);

		if(vright<=left || right<=vleft) return;
		if(left<=vleft && vright<=right){
			range_query->UpdateLazy(lazy[index],x,vleft,vright);
			lazy_flag[index] = true;
			Evaluate(index,vleft,vright);
		}
		else{
			UpdateRange(left,right,x,2*index+1,vleft,(vleft+vright)/2);
			UpdateRange(left,right,x,2*index+2,(vleft+vright)/2,vright);
			element[index] = range_query->CalculateCost(element[2*index+1],element[2*index+2]);
		}
	}
	// left<right
	T Find(int left,int right,int index=0,int vleft=0,int vright=-1){
		if(vright<0) vright = last_num;
		if(vright<=left || right<=vleft) return def_value;

		Evaluate(index,vleft,vright);
		if(left<=vleft && vright<=right) return element[index];

		T res_left = Find(left,right,2*index+1,vleft,(vleft+vright)/2);
		T res_right = Find(left,right,2*index+2,(vleft+vright)/2,vright);
		return range_query->CalculateCost(res_left,res_right);
	}
	T FindLeftmostValue(int left,int right,T value,int index=0,int vleft=0,int vright=-1){
		if(vright<0) vright = last_num;
		if(vright<=left || right<=vleft || element[index]!=value) return -1;

		if(index>=last_num-1) return index-(last_num-1);

		T res_left = FindLeftestValue(left,right,value,2*index+1,vleft,(vleft+vright)/2);
		if(res_left!=-1) return res_left;
		return FindLeftmostValue(left,right,value,2*index+2,(vleft+vright)/2,vright);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	string S=in<string>();
	vector<vector<ll>> V(26,vector<ll>(N+1,0));
	REP(i,N){
		V[S[i]-'a'][i+1]++;
		REP(j,26){
			V[j][i+1]+=V[j][i];
		}
	}

	SegmentTree<ll> ST[26];
	REP(i,26){
		ST[i].Construct(V[i],0);
	}
	int Q=in();
	LOOP(Q){
		int q=in();
		if(q==1){
			int i=in();
			char c=in<char>();
			int v=S[i-1]-'a';
			ST[v].UpdateRange(i,N+2,-1);
			ST[c-'a'].UpdateRange(i,N+2,1);
			S[i-1]=c;
		}
		else{
			int l=in()-1,r=in();
			int S=0;
			REP(i,26){
				auto la=ST[i].Find(l,l+1);
				auto ra=ST[i].Find(r,r+1);
				if(ra!=la) S++;
			}
			out(S);
		}
	}

	return 0;
}


Measured memory_bytes: 533976