#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
  int n,q;
  string s;
  cin >> n;
  cin >> s;
  cin >> q;
  vector<set<int>> table(26);
  rep(i,s.size()) table[s[i]-'a'].insert(i);
  rep(query,q){
    int com;cin >> com;
    if(com == 1){
      int i;
      char ch;
      cin >> i >> ch;
      --i;
      table[s[i]-'a'].erase(i);
      s[i] = ch;
      table[ch-'a'].insert(i);
    }else{
      int ans = 0;
      int l,r;cin >> l >> r;
      --r;--l;
      rep(j,26){
        set<int>::iterator it = table[j].lower_bound(l);
        if(it != table[j].end() && *it <= r) ans++;
      }
      printf("%d\n",ans);
    }
  }
}