#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	string s; cin >> s;
	vector<set<int> > alph(26);
	vector<int> ind(n);

	for (int i = 0; i < n; ++i)
	{
		alph[s[i] - 'a'].insert(i);
		ind[i] = s[i] - 'a';
	}

	int q; cin >> q;
	for (int i = 0; i < q; ++i)
	{
		int x; cin >> x;
		if (x == 1) {
			int i; char c; cin >> i >> c; i--;
			alph[ind[i]].erase(i);
			alph[c - 'a'].insert(i);
			ind[i] = c - 'a';
		}
		else {
			int l, r; cin >> l >> r;
			int ans = 0;
			for (int i = 0; i < 26; ++i)
			{
				if (alph[i].lower_bound(l-1) != alph[i].upper_bound(r-1)) ans++;
			}
			cout << ans << endl;
		}
	}

	return 0;
}