#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =5e5+5;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }
	   
	  int tr[4*N][26];
	  string s;
	  vi v(26,0);
	  
	  void build(int nd,int st,int ed) {
		      if(st==ed) {
				    tr[nd][s[st]-'a']++;
				    return;
				  }
				  int mid=(st+ed)>>1;
				  build(2*nd,st,mid);
				  build(2*nd+1,mid+1,ed);
				  rep(i,0,26)
				   tr[nd][i]=tr[2*nd][i]+tr[2*nd+1][i];	   
		  }
		  
	 void update(int nd,int st,int ed,int l,char ch) {
		     if(st>l || ed<l || st>ed) return;
		     if(st==ed) {
				   tr[nd][s[st]-'a']--;
				   tr[nd][ch-'a']++;
				   s[st]=ch;
				   return;
				 }
		    int mid=(st+ed)>>1;
		    update(2*nd,st,mid,l,ch);
		    update(2*nd+1,mid+1,ed,l,ch);
		    rep(i,0,26) 
		      tr[nd][i]=tr[2*nd][i]+tr[2*nd+1][i];		 
		 }	
		 
	 void query(int nd,int st,int ed,int l,int r) {
		    if(st>r || ed<l) return ;
		    if(st>=l && ed<=r) {
				   rep(i,0,26)
				     if(tr[nd][i]) v[i]++;
				     return;
				 }
		     int mid=(st+ed)>>1;
		     query(2*nd,st,mid,l,r);
		     query(2*nd+1,mid+1,ed,l,r);
		        		 		 
		 }	   
		   
	  

	 void solve() {	    
			int n,q;
			cin>>n;
			cin>>s;
			
			build(1,0,n-1);
			//~ rep(i,0,4*n) {
				 //~ cout<<i<<"  ";
				  //~ rep(j,0,26)
				    //~ cout<<tr[i][j]<<" ";
				    //~ cout<<endl;
				//~ }
			  
			
		    cin>>q;
			
			while(q--) {
				    int x,cnt=0;
				    char ch;
				    cin>>x;
				    if(x==1) {
						  int l;
						  cin>>l>>ch;						  
						  --l;
						  //~ if(s[l]==ch) continue;
						  update(1,0,n-1,l,ch);
						  
							//~ rep(i,0,4*n) {
								 //~ cout<<i<<"  ";
								  //~ rep(j,0,26)
									//~ cout<<tr[i][j]<<" ";
									//~ cout<<endl;
								//~ }			  
						    					  					  					   
						}
					else  {
						   //~ if(q==0) {
							     //~ rep(i,0,4*n) {
								 //~ cout<<i<<"  ";
								  //~ rep(j,0,26)
									//~ cout<<tr[i][j]<<" ";
									//~ cout<<endl;
								//~ }
							  //~ }
							    
						   rep(i,0,26) v[i]=0;
						   int l,r,cnt=0;
						   cin>>l>>r;
						   --l;--r;
						   query(1,0,n-1,l,r);	
						   rep(i,0,26) 
						     if(v[i]) cnt++;
						     cout<<cnt<<endl;			   
						}	
				}        
	 }
	
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	   solve();
	   
	   
	   return 0;	   
}


Measured memory_bytes: 215964