#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

template <typename T>
struct SegmentTree
{
    using F = function<T(T, T)>;
    int n;
    F f;
    T ti;
    vector<T> dat;

    SegmentTree() {}
    SegmentTree(F f, T ti) : f(f), ti(ti) {}

    void init(int n_)
    {
        n = 1;
        while (n < n_)
            n <<= 1;
        dat.assign(n << 1, ti);
    }

    void build(const vector<T> &v)
    {
        int n_ = v.size();
        init(n_);
        for (int i = 0; i < n_; i++)
            dat[n + i] = v[i];
        for (int i = n - 1; i; i--)
            dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }

    void set_val(int k, T x)
    {
        dat[k += n] += x;
        while (k >>= 1)
            dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }

    T query(int a, int b)
    {
        if (a >= b)
            return ti;
        T vl = ti, vr = ti;
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1)
        {
            if (l & 1)
                vl = f(vl, dat[l++]);
            if (r & 1)
                vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }

    template <typename C>
    int find(int st, C &check, T &acc, int k, int l, int r)
    {
        if (l + 1 == r)
        {
            acc = f(acc, dat[k]);
            return check(acc) ? k - n : -1;
        }
        int m = (l + r) >> 1;
        if (m <= st)
            return find(st, check, acc, (k << 1) | 1, m, r);
        if (st <= l && !check(f(acc, dat[k])))
        {
            acc = f(acc, dat[k]);
            return -1;
        }
        int vl = find(st, check, acc, (k << 1) | 0, l, m);
        if (~vl)
            return vl;
        return find(st, check, acc, (k << 1) | 1, m, r);
    }

    template <typename C>
    int find(int st, C &check)
    {
        T acc = ti;
        return find(st, check, acc, 1, 0, n);
    }
};

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    string s;
    cin >> n >> s >> q;
    auto f = [](int a, int b) { return a + b; };
    vector<SegmentTree<int>> al(26, SegmentTree<int>(f, 0));
    vector<int> v(n, 0);
    rep(i, 26) al[i].build(v);
    rep(i, n)
    {
        int num = s[i] - 'a';
        al[num].set_val(i, 1);
    }
    while (q--)
    {
        int a;
        cin >> a;
        if (a == 1)
        {
            int b;
            string c;
            cin >> b >> c;
            b--;
            int num1 = s[b] - 'a';
            int num2 = c[0] - 'a';
            s[b] = c[0];
            al[num1].set_val(b, -1);
            al[num2].set_val(b, 1);
        }
        else
        {
            int b, c;
            cin >> b >> c;
            b--, c--;
            int cnt = 0;
            rep(i, 26)
            {
                int tmp = min(1LL, al[i].query(b, c + 1));
                cnt += tmp;
            }
            cout << cnt << endl;
        }
    }
}


Measured memory_bytes: 217884