#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

template <typename Monoid>
class SegmentTree {
public:
    using F = function<Monoid(Monoid, Monoid)>;

    vector<int> node;
    int size;
    int n;
    F f;
    Monoid ie;

    SegmentTree(vector<int> in, F f, Monoid ie) : f(f), ie(ie) {
        int in_sz = in.size();
        n = 1;
        while (n < in_sz) {
            n *= 2;
        }
        size = n * 2 - 1;
        node.resize(size, 0);
        for (int i = 0; i < in_sz; i++) {
            node[n - 1 + i] = in[i];
        }
        init_dfs(0);
    }

    int init_dfs(int now) {
        if (2 * now + 1 >= size)
            return node[now];
        node[now] = f(init_dfs(2 * now + 1), init_dfs(2 * now + 2));
        return node[now];
    }

    void add(int index, int val) {
        index += n - 1;
        node[index] += val;
        while (index > 0) {
            index = (index - 1) / 2;
            node[index] = f(node[2 * index + 1], node[2 * index + 2]);
        }
    }

    void update(int index, int val) {
        index += n - 1;
        node[index] = val;
        while (index > 0) {
            index = (index - 1) / 2;
            node[index] = f(node[2 * index + 1], node[2 * index + 2]);
        }
    }

    //半開区間[l,r)に注意
    int query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

private:
    int _query(int a, int b, int now, int l, int r) {
        if (r <= a || b <= l)
            return ie;
        if (a <= l && r <= b)
            return node[now];
        int val_l = _query(a, b, 2 * now + 1, l, (l + r) / 2);
        int val_r = _query(a, b, 2 * now + 2, (l + r) / 2, r);
        return f(val_l, val_r);
    }
};

signed main() {
    cin >> N >> S;
    vvi memo(26, vi(N, 0));
    REP(j, N) {
        int x = S[j] - 'a';
        memo[x][j] = 1;
    }
    dump('z' - 'a');
    vector<SegmentTree<int>> sts;
    REP(i, 26) {
        auto f = [](int x, int y) {
            return x + y;
        };
        sts.emplace_back(SegmentTree<int>(memo[i], f, 0));
    }
    cin >> Q;
    REP(q, Q) {
        int x;
        cin >> x;
        if (x == 1) {
            int a;
            char b;
            cin >> a >> b;
            a--;
            int tmp1 = S[a] - 'a';
            int tmp2 = b - 'a';
            S[a] = b;
            if (tmp1 != tmp2) {
                sts[tmp1].update(a, 0);
                sts[tmp2].update(a, 1);
            }

        } else {
            int a, b;
            ans = 0;
            cin >> a >> b;
            REP(i, 26) {
                //dump(sts[i].query(a, b + 1));
                if (sts[i].query(a - 1, b) > 0) {
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 188884