#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;

int main(){
    int n,q;
    string s;
    cin>>n>>s>>q;
    vector<set<int>>se(26);
    rep(i,n)se[s[i]-'a'].insert(i);
    rep(i,q){
        int a,b; cin>>a>>b;
        b--;
        if(a==1){
            char c; cin>>c;
            se[s[b]-'a'].erase(b);
            s[b]=c;
            se[s[b]-'a'].insert(b);
        }
        else{
            int c; cin>>c;
            c--;
            int ans=0;
            rep(j,26){
                auto it=se[j].lower_bound(b);
                if(*it<=c&&it!=se[j].end())ans++;
            }
            printf("%d\n",ans);
        }
    }
}