
// Problem : E - Simple String Queries
// Contest : AtCoder - AtCoder Beginner Contest 157
// URL : https://atcoder.jp/contests/abc157/tasks/abc157_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 500005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int st[maxn][26];
int n,q;
string str;
void update(int j,int val)
{
	int i=j;
	while(i<=n)
	{
		st[i][val]++;
		i+=(i&-i);
	}
}
int ans[26];
void query(int ind,int flag)
{
	int i=ind;
	while(i>0)
	{
		for(int j=0;j<26;j++)
		{
			if(flag)
				ans[j]+=st[i][j];
			else ans[j]-=st[i][j];
		}
		i-=(i&-i);
	}
}
void solve()
{
	cin >> n;
	cin >> str;
	cin >> q;
//	build(1,0,n-1);
	for(int i=0;i<n;i++)
	update(i+1,str[i]-'a');
	while(q--)
	{
		int t;
		cin >> t;
		if(t==1)
		{
			int i;
			char x;
			cin >> i >> x;
			update(i,x-'a');
		}
		else{
			int i,j;
			cin >> i >> j;
			//cout << i <<" "<<j<<"\n";
			query(j,1);
			query(i-1,0);
			int cnt=0;
			rep(k,0,26){
				if(ans[k]>0)
				{
					//cout << (char)(k+'a') <<" ";
					cnt++;
					}
				ans[k]=0;
			}
			cout << cnt <<"\n";
		}
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}
