#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define vss vector< vector<string> >
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

struct SegmentTree {
    private:
        vl arr;
        ll size;
        ll n;
        vl value;
    public:
        SegmentTree(vl array){
            arr = array; 
            size = calc_size(arr);
            n = (size + 1) / 2;
            value = vl(size, 0); // custom
        }

        ll calc_size(vl array){
            int i = 1;
            while(i < array.size()) i <<= 1;
            return (i << 1) - 1;
        }

        void update(ll i, ll x){
            i += n - 1;
            value[i] = x;
            while(i > 0){
                i = (i-1) / 2;
                value[i] = value[2*i+1] || value[2*i+2];
            }
        }

        ll query(ll l, ll r){
            return _query(l, r+1, 0, 0, n);
        }
    
        ll _query(ll l, ll r, ll node_i, ll node_l, ll node_r){
            if(node_r <= l || r <= node_l) return 0; // custom
            if(l <= node_l && node_r <= r) return value[node_i];
            ll c1 = _query(l, r, 2 * node_i + 1, node_l, (node_l + node_r) / 2);
            ll c2 = _query(l, r, 2 * node_i + 2, (node_l + node_r) / 2, node_r);
            return c1 || c2;
        }
        void print(){
            DEBUG_VEC(value);
        }
};

int main(){
    ll N; cin >> N;
    string S; cin >> S;
    ll Q; cin >> Q;

    vector<SegmentTree> trees(26, SegmentTree(vl(N, 0)));

    for(int i=0; i<S.length(); i++){
        int j = (S[i] - 'a');
        trees[j].update(i, 1);
    }
    /* int t, l, r; */
    /* char c; */
    vs q;
    vs a;
    vs b;
    rep(i, 0, Q){
        string x, y, z;
        cin >> x >> y >> z;
        q.pb(x);
        a.pb(y);
        b.pb(z);
    }
    vi ans;
    rep(k, 0, Q){
        int t = stoi(q[k]);
        if(t == 1){
            int l = stoi(a[k]);
            l--;
            trees[S[l] - 'a'].update(l, 0); 
            S[l] = b[k][0];
            trees[S[l] - 'a'].update(l, 1);
        } else {
            int l = stoi(a[k]);
            int r = stoi(b[k]);
            l--; r--;
            ll cnt = 0;
            rep(i, 0, 26){
                cnt += trees[i].query(l, r);
            }
            ans.pb(cnt);
        }
    }
    rep(i, 0, ans.size()) cout << ans[i] << endl;
    return 0;
}




Measured memory_bytes: 331456