#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

using ull = unsigned long long;

constexpr ll initVal = 0LL;     //TODO: fix type and value
constexpr ll initLazy = 1LL<<60;    //TODO: fix type and value
constexpr ll RangeOutVal = 0LL; // TODO: fix type and value
template <typename T>
struct Node {
    T val;
    T lazy;
    ull l, r;
    Node<T>* l_node = nullptr;
    Node<T>* r_node = nullptr;
    Node(ull l, ull r, const T& val = initVal) : l(l), r(r), val(val), lazy(initLazy) {}
    T getVal() {
        return (lazy == initLazy ? val : lazy*(r-l)); //TODO: fix
    }
    T f1(const T& a, const T& b) {
        return a+b;               //TODO: fix
    }
    T f2(const T& a, const T& b) {
        return b;                       //TODO: fix
    }
    void push() {
        if(r - l > 1) {
            auto m = (l+r)/2;
            {
                if(l_node == nullptr) l_node = new Node(l, m);
                if(lazy != initLazy) l_node->lazy = f2(l_node->lazy, this->lazy);
            }
            {
                if(r_node == nullptr) r_node = new Node(m, r);
                if(lazy != initLazy) r_node->lazy = f2(r_node->lazy, this->lazy); 
            }
        }
        val = getVal();
        lazy = initLazy;
    }
    void fix() {
        if(r - l == 1) return;
        val = f1(l_node->getVal(), r_node->getVal());
    }
    T query(ull qL, ull qR) {
        if(qR <= l || r <= qL) return RangeOutVal;
        if(qL <= l && r <= qR) return getVal();
        if(r - l == 1)  return getVal();

        push();
        T l_val = l_node->query(qL, qR), r_val = r_node->query(qL, qR);
        return f1(l_val, r_val);
    }
    void update(ull uL, ull uR, const T& uVal) {
        if(uR <= l || r <= uL) return;
        if(uL <= l && r <= uR) lazy = f2(lazy, uVal);
        else {
            push();
            l_node->update(uL, uR, uVal);
            r_node->update(uL, uR, uVal);
            fix();
        }
    }
    void printNode() {
        cout << "(" << l <<", " << r << ") -> " << val << ", " << lazy << endl;
        if(l_node != nullptr) l_node->printNode(); 
        if(r_node != nullptr) r_node->printNode(); 
    }
};

template <typename T>
struct DynamicLazySegTree {
    Node<T> root;
    DynamicLazySegTree(ull l, ull r, const T& val) : root(l, r, val) {}
    T query(ull l, ull r) {
        return root.query(l, r);
    }
    void update(ull l, ull r, const T& val) {
        root.update(l, r, val);
    }
};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    int q;
    cin >> n >> s >> q;
    vector<DynamicLazySegTree<ll>> st(26, DynamicLazySegTree<ll>(0, n, 0));
    rep(i, n) st[s[i]-'a'].update(i, i+1, 1);
    rep(_, q) {
        int x;
        cin >> x;
        if(x == 1) {
            int id;
            char c;
            cin >> id >> c;
            --id;
            st[s[id]-'a'].update(id, id+1, 0);
            st[c - 'a'].update(id, id+1, 1);
            s[id] = c;
        }
        else {
            int l, r;
            cin >> l >> r;
            --l;
            int ans = 0;
            rep(i, 26) ans += (st[i].query(l, r) > 0 ? 1 : 0);
            cout << ans << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 556700