#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
// ------------------ Debugging ------------------
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[ " << *it << " = " << a << " ] ";
    err(++it, args...);
}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}
template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
// -----------------------------------------------
class BIT{
public:
	vector<int> bit;
	int N;
	/**
     * Creating tree is like updating Fenwick tree for every value in array
     */
	BIT() = default;
	BIT(vector<int> arr){ // set the argument accordingly to the array type
		N = arr.size();
		bit.assign(N+1, 0);
		for (int i = 1; i <= N; i++) {
			updateBIT(arr[i-1], i);
		}
	}
	/**
     * Start from index+1 if you updating index in original array. Keep adding this value 
     * for next node till you reach outside range of tree
     */
	void updateBIT(int val, int idx) {
		while (idx < N+1) {
			bit[idx] += val;
			idx = getNext(idx);
		}
	}
	void update(int val, int idx){
		int diff = val - bit[idx];
		updateBIT(diff, idx);
	}

	/**
     * To get next
     * 1) 2's complement of get minus of index
     * 2) AND this with index
     * 3) Add it to index
     */
	int getNext(int idx) {
		return idx + (idx & -idx);
	}

	/**
     * Start from index+1 if you want prefix sum 0 to index. Keep adding value
     * till you reach 0
     */
	int getSum(int idx) {
		idx++;
		int sum = 0;
		while (idx > 0) {
			sum += bit[idx];
			idx = getParent(idx);
		}
		return sum;
	}
	int getSum(int l, int r) {
		return getSum(r-1) - getSum(l-2);
	}
	/**
     * To get parent
     * 1) 2's complement to get minus of index
     * 2) AND this with index
     * 3) Subtract that from index
     */
	int getParent(int idx) {
		return idx - (idx & -idx);
	}

};
void solve() {
	int n;
	string s;
	cin >> n >> s;
	vector<vector<int>> store(26, vector<int>(n));
	for (int i = 0; i < n; i++) {
		store[s[i] - 'a'][i] = 1;
	}
	vector<BIT> forCh(26);
	for (int i = 0; i < 26; i++) {
		forCh[i] = BIT(store[i]);
	}
	int Q;
	cin >> Q;
	while (Q--) {
		int type;
		cin >> type;
		if (type == 1) {
			int idx;
			char ch;
			cin >> idx >> ch;
			forCh[s[idx-1] - 'a'].updateBIT(-1, idx);
			forCh[ch-'a'].updateBIT(1, idx);
			s[idx-1] = ch;
		} else {
			int cnt = 0, l, r;
			cin >> l >> r;
			for (int i = 0; i < 26; i++) {
				cnt += (forCh[i].getSum(l, r)) > 0;
			}
			cout << cnt << endl;
		}
	}

}
signed main() {

	fastIO

	solve();

	return 0;
}


Measured memory_bytes: 210832