#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
ull N, n_query;
string s;
vector<ull> ans;
vector<set<ull>> char_place(26);
void change_char(ull i, char changed, char original) {
  if (changed == original) return;
  char_place[original - 'a'].erase(i);
  char_place[changed - 'a'].insert(i);
}
ull num_chars(ull l, ull r) {
  ull sum(0);
  for (char c = 0; c < 26; c++) {
    const auto cp = char_place[c];
    const auto f = cp.lower_bound(l);
    const auto first_place = *f;
    if (f != cp.end() && first_place <= r) {
      sum++;
    }
  }
  return sum;
}
int main(int argc, char const *argv[]) {
  cin >> N;
  cin >> s;
  for (ll i = (0); i < (N); i++) {
    char_place[s[i] - 'a'].insert(i);
  }
  cin >> n_query;
  for (ll _ = (0); _ < (n_query); _++) {
    int t;
    cin >> t;
    if (t == 1) {
      ull i;
      char c;
      cin >> i >> c;
      change_char(i - 1, c, s[i - 1]);
    } else {
      ull l, r;
      cin >> l >> r;
      ans.push_back(num_chars(l - 1, r - 1));
    }
  }
  for (const auto a : ans) {
    cout << a << endl;
  }
  return 0;
}
