//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)


typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


//区間和
struct RSQ{
    ll n;
    vector<ll>data;
    RSQ(ll vs){
        n=1;
        while(n<vs)n*=2;
        data.resize(2*n-1,0);
    }
    void update(ll k,ll a){
        k+=n-1;
        data[k]=a;
        while(k>0){
            k=(k-1)/2;
            data[k]=data[2*k+1]+data[2*k+2];
        }
    }
    void add(ll k,ll a){
        k+=n-1;
        data[k]+=a;
        while(k>0){
            k=(k-1)/2;
            data[k]=data[2*k+1]+data[2*k+2];
        }
    }
    ll query(ll a,ll b,ll k,ll l,ll r){
        if(r<=a||b<=l)return 0;
        if(a<=l&&r<=b){
            return data[k];
        }else{
            ll vl=query(a,b,2*k+1,l,(l+r)/2);
            ll vr=query(a,b,2*k+2,(l+r)/2,r);
            return vl+vr;
        }
    }
    ll query(ll a,ll b){return query(a,b,0,0,n);}//[a,b)の和
};

int main(){fastio
    ll n;cin>>n;
    string s;cin>>s;
    vector<RSQ>st;
    rep(i,0,25){
        RSQ z(n);
        st.pb(z);
    }
    rep(i,0,s.size()-1){
        st[s[i]-'a'].update(i,1);
    }
    ll q;cin>>q;
    while(q--){
        ll a,b;cin>>a>>b;
        b--;
        if(a==1){
            char c;cin>>c;
            rep(i,0,25)st[i].update(b,0);
            st[c-'a'].update(b,1);
        }else{
            ll c;cin>>c;
            ll ans=0;
            rep(i,0,25){
                if(st[i].query(b,c)>=1)ans++;
            }
            cout<<ans<<endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 221976