#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 5;
set<int> pos[256];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    pos[s[i]].insert(i + 1);
  }
  int q;
  cin >> q;
  for (int i = (int)1; i <= (int)q; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      int x;
      char c;
      cin >> x >> c;
      pos[s[x]].erase(x);
      pos[c].insert(x);
      s[x] = c;
    } else {
      int x, y;
      cin >> x >> y;
      int ret = 0;
      for (int c = (int)'a'; c <= (int)'z'; c++) {
        auto it = pos[c].lower_bound(x);
        if (it != pos[c].end() && *it <= y) ret++;
      }
      cout << ret << endl;
    }
  }
}
