// ABC157E - Simple String Queries

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

int main() {
	int N;
	cin >> N;

	vector< set<int> > alpha(26);

	string S;
	cin >> S;

	for (int i = 0; i < N; i++) {
		alpha.at(S[i] - 'a').insert(i + 1);
	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int op;
		cin >> op;
		if (op == 1) {
			int iq;
			char cq;
			cin >> iq >> cq;

			alpha.at(S[iq - 1] - 'a').erase(iq);
			alpha.at(cq - 'a').insert(iq);
			S[iq - 1] = cq;
		} else if (op == 2) {
			int l, r;
			cin >> l >> r;

			int answer = 0;
			for (int j = 0; j < 26; j++) {
				set<int>::iterator it;
				it = alpha.at(j).lower_bound(l);
				if ((it != alpha.at(j).end())&&(*it <= r)) {
					answer++;
				}
			}
			cout << answer << endl;
		}
	}
}
