#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
int main(void){
    int n,q;string s;cin>>n>>s>>q;
    vector<set<int>> is(26);
    rep(i,n) is[s[i]-'a'].insert(i);
    rep(qi,q){
        int ty;cin>>ty;
        if(ty==1){
            int i;char r;cin>>i>>r;i--;
            is[s[i]-'a'].erase(i);
            s[i]=r;
            is[s[i]-'a'].insert(i);
        }else{
            int l,r;cin>>l>>r;l--;r--;
            int res=0;
            rep(i,26){
                auto itr= is[i].lower_bound(l);
                if(itr!=is[i].end()&&*itr<=r)res++;
            }
            cout<<res<<endl;
        }
    }
}
