#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll n, q;
  string s;
  cin >> n;
  cin >> s;
  cin >> q;

  map<char, set<ll>> m;
  for (ll i = 0; i < (ll) s.size(); i++) {
    m[s[i]].insert(i);
  }

  for (ll i = 0; i < q; i++) {
    int num;
    cin >> num;
    if (num == 1) {
      ll iq;
      char cq;
      cin >> iq >> cq;
      iq--;
      m[s[iq]].erase(iq);
      s[iq] = cq;
      m[cq].insert(iq);
    } else {
      ll lq, rq;
      cin >> lq >> rq;
      lq--; rq--;

      ll ans = 0;
      for (char c = 'a'; c <= 'z'; c++) {
        auto it = m[c].lower_bound(lq);
        if (it == m[c].end()) continue;
        // cout << c << " " << *it << endl;
        if (*it <= rq) ans++;
      }
      cout << ans << endl;
    }
  }
}
