#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;


int main(){
    ll N; cin >> N;
    string S; cin >> S;
    ll Q; cin >> Q;
    vector<set<ll>> sg(26);
    rep(i, 0, 26){
        //sg[i].insert(INF);
    }
    rep(i, 0, N){
        ll d = S[i] - 'a';
        sg[d].insert(i);
    }
    rep(i, 0, Q){
        ll a; cin >> a;
        if(a == 1){
            ll x; char q;
            cin >> x >> q;
            x--;
            if(q == S[x]){
                continue;
            }
            ll e = S[x] - 'a', f = q - 'a';
            S[x] = q;
            sg[e].erase(x); sg[f].insert(x);
        }else{
            ll l, r; cin >> l >> r;
            l--; r--;
            ll c = 0;
            rep(j, 0, 26){
                if(*lower_bound(sgj].begin(), sgj].end(), l) <= r){
                    //char t = 'a' + j;
                    //prtl(t);
                    c++;
                }
            }
            prtl(c);
        }
    }
}