#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

class SegmentTree {
    int n;
    vector<ll> node;

public:
    SegmentTree(vector<ll> v) {
        n = 1;
        int s = v.size();
        while (n < s) n *= 2;
        node.resize(2 * n - 1, 0);
        for (int i = 0; i < s; i++) node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--) node[i] = node[2 * i + 1] + node[2 * i + 2];
    }

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

    void inc(int x) {
        x += (n - 1);
        if (node[x]) return;
        node[x]++;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = node[2 * x + 1] + node[2 * x + 2];
        }
    }

    void dec(int x) {
        x += (n - 1);
        if (!node[x]) return;
        node[x]--;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = node[2 * x + 1] + node[2 * x + 2];
        }
    }

    ll find(int a, int b, int k = 0, int l = 0, int r = -1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];

        ll vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
        return vl + vr;
    }
};

void solve() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<SegmentTree> st;
    REP(i, 26) {
        vl v(n, 0);
        char c = (char)(i + 'a');
        REP(j, n) if (c == s[j]) v[j]++;
        SegmentTree sg(v);
        st.emplace_back(sg);
    }
    int a, b;
    while (q--) {
        cin >> a >> b;
        if (a == 1) {
            char c;
            cin >> c;
            if (s[b - 1] == c) continue;
            st[(int)(c - 'a')].inc(b - 1);
            st[(int)(s[b - 1] - 'a')].dec(b - 1);
            s[b - 1] = c;
        } else {
            int c;
            cin >> c;
            int ans = 0;
            REP(i, 26) if (st[i].find(b - 1, c)) ans++;
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 233744