#include <bits/stdc++.h>
using namespace std;
bool myCmp(pair<int, int> &p1, pair<int, int> &p2) {
  return p1.first > p2.first;
}
unsigned long long choose(unsigned long long n, unsigned long long k) {
  if (k > n) {
    return 0;
  }
  unsigned long long r = 1;
  for (unsigned long long d = 1; d <= k; ++d) {
    r *= n--;
    r /= d;
  }
  return r;
}
int toInt(string str) {
  int num;
  istringstream iss(str);
  iss >> num;
  return num;
}
template <class T>
string toStr(T par) {
  ostringstream oss;
  oss << par;
  return oss.str();
}
const int MAXN = 6 * 10e5;
int pre[MAXN][26] = {0};
int wak[MAXN];
map<int, pair<char, char>> inserted;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  int n, t;
  string s;
  int q;
  cin >> n;
  cin >> s;
  cin >> q;
  for (int i = 1; i <= s.size(); ++i) {
    for (int j = 0; j < 26; j++) {
      pre[i][j] = pre[i - 1][j];
    }
    pre[i][s[i - 1] - 'a']++;
  }
  while (q--) {
    cin >> t;
    if (t == 1) {
      int idx;
      char c;
      cin >> idx >> c;
      idx--;
      if (c == s[idx]) continue;
      inserted[idx] = make_pair(c, s[idx]);
    } else {
      int ans = 0;
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      if (l == r) {
        cout << 1 << endl;
        continue;
      }
      auto lb = inserted.lower_bound(l);
      int temp_alpha[26] = {0};
      if ((lb != inserted.end()) && (lb->first <= r)) {
        auto ub = inserted.upper_bound(r);
        r++;
        for (auto it = lb; it != ub; it++) {
          temp_alpha[it->second.first - 'a']++;
          temp_alpha[it->second.second - 'a']--;
        }
      } else {
        r++;
      }
      for (int i = 0; i < 26; ++i)
        ans += ((pre[r][i] + temp_alpha[i]) > pre[l][i]);
      cout << ans << endl;
    }
  }
  return 0;
}
