#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL << 60;
ll M = 1000000007;
int main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  ll Q;
  cin >> Q;
  vector<set<ll>> sg(26);
  for (ll i = 0; i < 26; i++) {
  }
  for (ll i = 0; i < N; i++) {
    ll d = S[i] - 'a';
    sg[d].insert(i);
  }
  for (ll i = 0; i < Q; i++) {
    ll a;
    cin >> a;
    if (a == 1) {
      ll x;
      char q;
      cin >> x >> q;
      x--;
      if (q == S[x]) {
        continue;
      }
      ll e = S[x] - 'a', f = q - 'a';
      S[x] = q;
      sg[e].erase(x);
      sg[f].insert(x);
    } else {
      ll l, r;
      cin >> l >> r;
      l--;
      r--;
      ll c = 0;
      for (ll j = 0; j < 26; j++) {
        if (*lower_bound(sg[j].begin(), sg[j].end(), l) <= r) {
          c++;
        }
      }
      cout << (c) << "\n";
    }
  }
}
