#include <bits/stdc++.h>
using namespace std;
const long long INF = INT_MAX;
const int MOD = 1000000007;
struct SegmentTree {
 private:
  int n;
  vector<int> node;

 public:
  SegmentTree(vector<int> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, 0);
    for (int i = 0; i < sz; i++) node.at(i + n - 1) = v.at(i);
    for (int i = n - 2; i >= 0; i--)
      node.at(i) = node.at(2 * i + 1) + node.at(2 * i + 2);
  }
  void add(int x, int val) {
    x += n - 1;
    node.at(x) += val;
    while (x > 0) {
      x = (x - 1) / 2;
      node.at(x) = node.at(2 * x + 1) + node.at(2 * x + 2);
    }
  }
  int getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return node.at(k);
    int vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
    return vl + vr;
  }
};
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<SegmentTree> seg;
  for (int i = 0; i < 27; i++) {
    SegmentTree www(vector<int>(n, 0));
    seg.push_back(www);
  }
  for (int i = 0; i < n; i++) {
    seg.at(int(s.at(i) - 'a')).add(i, 1);
  }
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if (a == 1) {
      int b;
      char c;
      cin >> b >> c;
      --b;
      if (s.at(b) == c)
        continue;
      else {
        seg.at(int(c - 'a')).add(b, 1);
        s.at(b) = c;
      }
    } else {
      int b, c;
      cin >> b >> c;
      --b;
      --c;
      int ans = 0;
      for (int k = 0; k < 27; k++) {
        if (seg.at(k).getsum(b, c + 1) >= 1) ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
