#include <bits/stdc++.h>

using namespace std;


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;

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

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

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int type;
		cin >> type;
		if (type == 1) {
			int index;
			char ch;
			cin >> index >> ch;
			index--;
			char oldCharacter = s[index];
			s[index] = ch;
			freq[oldCharacter - 'a'].erase(index);
			freq[ch - 'a'].insert(index);
		}
		else {
			int left, right;
			cin >> left >> right;
			left--, right--;
			int res = 0;
			for (int j = 0; j < 26; j++) {
				auto it = freq[j].lower_bound(left);
				if (it == freq[j].end()) continue;
				int val = *it;
				if (val >= left && val <= right) res++;
			}

			cout << res << endl;
		}
	}
}