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

int main(){
    int n,q; string s; cin>>n>>s>>q;
    vector<set<int>> moji(26);
    rep(i,n) moji[s[i]-'a'].insert(i);
    rep(j,q){
        int which;
        cin>>which;
        if(which==1){
            int i; char c; cin>>i>>c; i--;
            moji[s[i]-'a'].erase(i);
            s[i] = c;
            moji[s[i]-'a'].insert(i);
        }else{
            int l,r,ans=0; cin>>l>>r; l--;
            rep(i,26){
                auto it = moji[i].lower_bound(l);
                if(it!=moji[i].end()&& *it<r) ans++;
            }
            cout << ans << endl;
        }
    }
}