#include <bits/stdc++.h>
using namespace std;
long long intpow(int n, int m) {
  if (m == 0) return 1;
  return n * intpow(n, m - 1);
}
long long gcd(long long n, long long m) {
  n = max(n, m);
  m = min(n, m);
  if (n % m == 0) return m;
  return gcd(m, n % m);
}
long long lcm(long long n, long long m) { return n * m / gcd(n, m); }
const int inf = 2147483647;
int n;
bool node[1000000][26];
void init(int n_) {
  while (n < n_) n *= 2;
  for (int i = 0; i < 2 * n - 1; i++) {
    for (int j = 0; j < 26; j++) node[i][j] = 0;
  }
}
void update(int i, char a, char b) {
  i += n - 1;
  int m1 = a - 97;
  int m2 = b - 97;
  node[i][m1] = 0;
  node[i][m2] = 1;
  while (i > 0) {
    i = (i - 1) / 2;
    node[i][m1] = node[i * 2 + 1][m1] || node[i * 2 + 2][m1];
    node[i][m2] = node[i * 2 + 1][m2] || node[i * 2 + 2][m2];
  }
}
int query(int a, int b, int k, int l, int r, int c) {
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b)
    return node[k][c];
  else {
    bool vl = query(a, b, k * 2 + 1, l, (l + r) / 2, c);
    bool vr = query(a, b, k * 2 + 2, (l + r) / 2, r, c);
    return vl || vr;
  }
}
int main() {
  int N, q;
  cin >> N;
  string s;
  cin >> s;
  cin >> q;
  n = 1;
  init(s.size());
  for (int i = 0; i < s.size(); i++) update(i, 'a', s[i]);
  for (int i = 0; i < q; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int j;
      char c;
      cin >> j >> c;
      j--;
      update(j, s[j], c);
      s.replace(j, 1, 1, c);
    }
    if (type == 2) {
      int l, r;
      cin >> l >> r;
      int sum = 0;
      for (int j = 0; j < 26; j++) sum += query(l - 1, r, 0, 0, n, j);
      cout << sum << endl;
    }
  }
}
