#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
	int n, q;
	string s;
	cin >> n >> s >> q;
	vector<set<int>> is(26);
	rep(i, n) is[s[i] - 'a'].insert(i);
	rep(ri, q) {
		int t; cin >> t;
		if (t == 1) {
			int i; char c;
			cin >> i >> c;
			i--;
			is[s[i] - 'a'].erase(i);
			s[i] = c;
			is[s[i] - 'a'].insert(i);
		}
		else {
			int l, r; cin >> l >> r;
			l--; r--;
			int ans = 0;
			rep(i, 26) {
				auto itr = is[i].lower_bound(l);
				if (itr != is[i].end() && *itr <= r) ans++;
			}
			cout << ans << endl;
		}
	}
	return 0;
}
