/**
 * Libraries
 */
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <iomanip>
#include <set>
#include <unordered_map>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

/**
 * macros
 */
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define repx(i,s,e,d) for(int i=s,i##_end=(e);i<i##_end;i+=d)
#define repxr(i,s,e,d) for(int i=s,i##_end=(e);i>i##_end;i+=d)
#define rept(n) for(int ___i___=0,i##_len=(n);___i___<i##_len;++___i___)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end());
#define CEIL(x, y) (((x) + (y) - 1) / (y))

/**
 * standard input helpers
 */
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
/**
 * debug tools
 */
#define DUMPOUT cout
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef LOCAL_
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif

/**
 * helpers
 */
typedef long long int lli;
typedef pair<int, int> ii;
typedef priority_queue<int, vector<int>, greater<int> > heapq;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;
// #define int long long int
// struct S{
//     bool operator<(const S& x) const {
//         return ;
//     }
// };
class BITree { // 1-index
    public:
        BITree(int _n) {
            n = _n;
            for (int i = 0; i <= n; i++) bit[i] = 0;
        }
        int sum(int i) {
            int s = 0;
            for (; i > 0; i -= i & -i) { // 最後の1ビット減算
                s += bit[i];
            }
            return s;
        }

        void add(int i, int x) {
            for (; i <= n; i += i & -i) {
                bit[i] += x;
            }
        }
    private:
        int bit[(1 << 19)  + 1], n;
};
signed main() {
    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;

    vector<BITree> bt(26, BITree(N));
    rep(i, N) {
        bt[S[i] - 'a'].add(i + 1, 1);
    }

    rept(Q) {
        int type;
        string _a, _b;
        cin >> type >> _a >> _b;
        if (type == 1) {
            dump(type, _a, _b);
            int iq = stoi(_a);
            char cq = _b[0];
            bt[S[iq - 1] - 'a'].add(iq, -1);
            bt[cq - 'a'].add(iq, 1);
            S[iq - 1] = cq;
        } else {
            dump(type, _a, _b);
            int lq = stoi(_a);
            int rq = stoi(_b);

            int ans = 0;
            rep(i, 26) {
                if (bt[i].sum(rq) - bt[i].sum(lq - 1) > 0) {
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 56184