#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
typedef vector<long long> vlint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<vector<long long>> vlint2;

// unionfind: 1-indexed
struct UnionFind{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    int n;

    UnionFind(int N) : par(N+1) { //最初は全てが根であるとして初期化
        n = N;
        for(int i = 0; i < N+1; i++) par[i] = -1;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry]; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        par[ry] = rx;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
lint func(lint x, lint y){
    return x | y;
}
struct SegmentTree{
    vlint tree;
    lint n;
    lint ide;

    SegmentTree(vlint v, lint id){
        ide = id;
        if (bitset<64>(v.size()).count() == 1){
            n = (1 << v.size());
        }
        else{
            int i = 31;
            while (i){
                if (v.size() & (1 << i)){
                    n = (1 << i+1);
                    break;
                }
                else {
                    i --;
                }
            }
        }
        vlint t((n << 1));
        rep(i, (n << 1)) t[i] = ide;
        tree = t;

        rep(i, v.size()){
            insert(i + 1, v[i]);
        }
    };
    void insert(lint index, lint value){
        lint i = index - 1 + n;
        tree[i] = value;
        update(i/2);
    }
    void update(lint index){

        if (index){
            tree[index] = func(tree[2 * index], tree[2 * index + 1]);
            update(index/2);
        }
    }
    //半開区間
    lint query(lint l, lint r){
        // 閉区間に直す
        lint res = ide;
        l = l - 1 + n;
        r = r - 2 + n;
        while ((r - l) > 0){
            if (l & 1){
                res = func(res, tree[l]);
                l ++;
            }
            if (!(r & 1)){
                res = func(res, tree[r]);
                r --;
            }
            l = l/2;
            r = r/2;
        }
        if (l == r) res = func(res, tree[l]);

        return res;
    }
    void show(){
        rep(i, (n << 1)){
            cout << tree[i] << " ";
        }
        cout << "\n";
    }
};

int main() {
    lint n;
    string s;
    lint q; cin >> n >> s >> q;
    vlint v(n);
    rep(i, n) v[i] = (1 << (int)(s[i] - 'a'));
    SegmentTree st(v, 0);

    rep(i, q){
        int type;
        lint a; cin >> type >> a;
        if (type == 1){
            char b; cin >> b;
            st.insert(a, (1 << (int)(b - 'a')));
        }
        else {
            lint b; cin >> b;
            lint ans = st.query(a, b+1);
            cout << bitset<32>(ans).count() << endl;
        }

    }

}


Measured memory_bytes: 25092