#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define NL endl
#define pi 2.0*acos(0.0)
#define mod 1e9+7
#define FOR(i,j,n)    for(ll i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

set<ll>cset[30];

int main(){
    fastIO;
    ll n,q,a,b,c,pos,ans = 0;
    string s;
    char d,curr;
    cin>>n>>s>>q;
    FOR(i,0,n){
        cset[s[i] - 'a'].insert(i+1);
    }
    FOR(i,0,26){
        cset[i].insert(1e18);
    }
    while(q--){
        cin>>a;
        if(a == 1){
            cin>>b>>d;
            curr = s[b-1];
            cset[curr - 'a'].erase(b);
            cset[d - 'a'].insert(b);
            s[b - 1] = d;
        }
        else{
            cin>>b>>c;
            ans = 0;
            FOR(i,0,26){
                if(cset[i].size()){
                    auto lower = cset[i].lower_bound(b);
                    if(*lower == 1e18){}
                    else{
                        ll val = *lower;
                        if(val >= b && val <= c) ans++;
                    }
                }
            }
            cout<<ans<<endl;
        }
    }
}
