#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
constexpr int32_t NUM_CHA = 26;

struct segment_tree {
  int NV;
  //vector<string> dat;
  vector<vector<int>> dat;

  inline void merge(const string& s1, const string& s2, string& res) {
    unordered_set<char> us;
    for (int j = 0; j < (int)s1.size(); j++) {
      us.emplace(s1[j]);
    }
    for (int j = 0; j < (int)s2.size(); j++) {
      us.emplace(s2[j]);
    }
    for (auto c : us) {
      res += c;
    }
    return;
  }

  inline void merge2(vector<int>& v1, vector<int>& v2, vector<int>& res) {
    for (int i = 0; i < NUM_CHA; i++) {
      res[i] = v1[i] + v2[i];
    }
    return;
  }
  
  segment_tree(int N, string& S) {
    NV = 1;
    while (NV < N) NV = NV << 1;
    dat.resize(NV*2 -1);
    //cout << "sg init: NV = " << NV << endl; 
    for (int i = 0; i < NV; i++) {
      //dat[i+NV-1] = S[i];
      dat[i+NV-1].resize(NUM_CHA, 0);
      if (i < (int)S.size()) {
        dat[i+NV-1][S[i] - 'a']++;
      }
    }
    for (int i = NV - 2; i >= 0; i--) {
      //merge(dat[i*2 + 1], dat[i*2 + 2], dat[i]);
      dat[i].resize(NUM_CHA, 0);
      merge2(dat[i*2 + 1], dat[i*2 + 2], dat[i]);
    }
  }

  void update(int idx, char val) {
    if (idx < 0) return;
    idx += NV - 1;
    //dat[idx] = val;
    int rm_idx = 0;
    for (int i = 0; i < NUM_CHA; i++) {
      if (dat[idx][i] == 1) {
        rm_idx = i;
        dat[idx][i] = 0;
      }
    }
    dat[idx][val - 'a']++;
    //cout << idx << ":" << dat[idx].first << "," << dat[idx].second << endl;
    while (idx > 0) {
      idx = (idx - 1) / 2;
      //merge(dat[idx*2 + 1], dat[idx*2 + 2], dat[idx]);
      dat[idx][val - 'a']++;
      dat[idx][rm_idx]--;
      //cout << idx << ":" << dat[idx].first << "," << dat[idx].second << endl;
    }
    return;
  }

  int query(int a, int b) {
    //string res;
    //unordered_set<char> res;
    //_query(a, b, 0, 0, NV, res);
    auto cnt = _query(a, b, 0, 0, NV);
    int res = 0;
    for (int i = 0; i < NUM_CHA; i++) {
      if (cnt[i] > 0) {
        res++;
      }
    }
    return res;
  }
  vector<int> _query(int a, int b, int k, int l, int r) {
    //cout << "query called :" << a << "," << b << "," << k << "," << l << "," << r << endl;
    if (r <= a || b <= l) return vector<int>(NUM_CHA, 0);
    if (a <= l && r <= b) {
      //res = dat[k];
      //for (int i = 0; i < (int) dat[k].size(); i++) {
      //  res.emplace(dat[k][i]);
      //}
      return dat[k];
    } else {
      auto v1 = _query(a, b, k*2 + 1, l, (l + r) / 2);
      auto v2 = _query(a, b, k*2 + 2, (l + r) / 2, r);
      vector<int> res(NUM_CHA, 0);
      merge2(v1, v2, res);
      return res;
      //cout << "querry return val: " << min(vr,vl).first << "," << min(vr,vl).second << endl;
    }
  }
};

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int32_t N, Q;
  cin >> N;
  string S;
  cin >> S;
  cin >> Q;
  
  segment_tree sg(N, S);
  vector<int> res_vect;
  for (int q = 0; q < Q; q++) {
    int type;
    cin >> type;
    int l,r;
    char c;
    if (type == 1) {
      cin >> l;
      cin >> c;
      sg.update(l-1, c);
    } else {
      cin >> l >> r;
      //string qs = sg.query(l - 1, r);
      //res_vect.push_back((int)qs.size());
      res_vect.push_back(sg.query(l-1, r));
    }
  }
  for (auto res : res_vect) {
    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 140444