#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

template <typename T>
class segmentTree {
private:
	T* tree;
	T paddingObj;
	std::function<T(T, T)> segfunc;
	int treeSize;
	int treeHeight;

	void initialize() {
		for (int i = treeHeight - 1; i >= 1; --i) {
			for (int counter = 0; counter < (1 << (i - 1)); ++counter) {
				int index = (1 << (i - 1)) - 1 + counter;
				tree[(1 << (i - 1)) - 1 + counter] = segfunc(tree[index * 2 + 1], tree[index * 2 + 2]);
			}
		}
	}

	void updateTree(int index) {
		if (index == 0) return;

		if (index % 2 == 0) --index;
		tree[(index - 1) / 2] = segfunc(tree[index], tree[index + 1]);
		updateTree((index - 1) / 2);
	}

	T query(int l, int r, int left, int right, int index) {
		if (l <= left && r >= right) {
			return tree[index];
		}
		else if (l > right || r < left) {
			return paddingObj;
		}
		else {
			return segfunc(query(l, r, left, (left + right) / 2, index * 2 + 1), query(l, r, (left + right) / 2 + 1, right, index * 2 + 2));
		}
	}
public:
	segmentTree(T *originalArray, int arraySize, T paddingObj, std::function<T(T, T)> func) {
		this->segfunc = func;
		this->paddingObj = paddingObj;

		treeHeight = 1;
		while ((1 << (treeHeight - 1)) < arraySize) ++treeHeight;
		treeSize = 1 << (treeHeight - 1);
		tree = new T[treeSize * 2 - 1];
		for (int i = 0; i < arraySize; ++i) tree[(treeSize - 1) + i] = originalArray[i];
		for (int i = arraySize; i < treeSize; ++i) tree[(treeSize - 1) + i] = paddingObj;

		initialize();
	}

	~segmentTree() {
		delete[] tree;
	}

	void update(int index, T x) {
		if (index >= treeSize || index < 0) {
			throw std::out_of_range("Index must be in [0, treeSize)");
			return;
		}

		tree[treeSize - 1 + index] = x;
		updateTree(treeSize - 1 + index);
	}

	T get(int l, int r) {
		if (l > r || l < 0 || r >= treeSize) {
			throw std::out_of_range("Both l and r must be in [0, treeSize) and l must be greater than r");
		}

		return query(l, r, 0, treeSize - 1, 0);
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	string s;
	cin >> n >> s;
	int q;
	cin >> q;
	vector<pair<int, pii>> query;
	pair<int, pii> x;
	char c;
	rep(i, q) {
		cin >> x.first;
		if (x.first == 1) {
			cin >> x.second.first >> c;
			x.second.second = 1 << (c - 'a');
		}
		else {
			cin >> x.second.first >> x.second.second;
		}

		query.push_back(x);
	}

	int* origin = new int[n];
	rep(i, n) origin[i] = 1 << (s[i] - 'a');
	
	segmentTree<int> tree(origin, n, 0, [](int a, int b) {return a | b; });
	vector<int> ans;
	rep(i, q) {
		if (query[i].first == 1) {
			tree.update(query[i].second.first - 1, query[i].second.second);
		}
		else {
			int flag = tree.get(query[i].second.first - 1, query[i].second.second - 1);
			int sum = 0;
			rep(i, 26) {
				if (flag & (1 << i)) ++sum;
			}

			ans.push_back(sum);
		}
	}

	rep(i, ans.size()) cout << ans[i] << "\n";

	return 0;
}


Measured memory_bytes: 10360