#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define mo 1000000007
#define MAX_N 500004
#define INF 2000000000
 
#define fast_io ios::sync_with_stdio(false)


set<int> st[26];

int main()
{
	int n, q, ty, l, r;
	char c;
	string s;
	cin >> n >> s >> q;
	for(int i = 0; i < n; ++i)
		st[s[i] - 'a'].insert(i);
	for(int i = 1; i <= q; ++i)
	{
		cin >> ty;
		if(ty == 1)
		{
			cin >> l >> c;
			l--;
			st[s[l] - 'a'].erase(l);
			st[c - 'a'].insert(l);
			s[l] = c;
		}  
		else
		{
			cin >> l >> r;
			l--;
			r--;
			int ans = 0;
			for(int i = 0; i < 26; ++i)
				if(st[i].lower_bound(l) != st[i].end() && *st[i].lower_bound(l) <= r)
					ans++;
			cout << ans << endl;
		}

	}



}   