#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>

using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

void precalc() {}

//#define solvsh
//#define multi

#ifdef solvsh

void solve() {

}

#else
typedef vector<int> vi;
#define INF 0x3f3f3f3f
#define FOR(i, n) for(int i = 0; i < n; i++)
template<class T>
T rnd(T l,T r){	//[l,r)
    using D = uniform_int_distribution<T>;
    static random_device rd;
    static mt19937 gen(rd());
    return D(l,r-1)(gen);
}
const int MAXN = 6e5 + 30;

int t[26][4 * MAXN];

char s[MAXN];

void build (int v, int tl, int tr, int letter) {
    if (tl == tr) {
        if (s[tl] - 'a' == letter) {
            t[letter][v] = 1;
        } else {
            t[letter][v] = 0;
        }
    } else {
        int tm = (tl + tr) / 2;
        build( v * 2, tl, tm, letter);
        build(v * 2 + 1, tm + 1, tr, letter);
        t[letter][v] = t[letter][v * 2] + t[letter][v * 2 + 1];
    }
}

int sum (int v, int tl, int tr, int l, int r, int letter) {
    if (l > r)
        return 0;
    if (l == tl && r == tr)
        return t[letter][v];
    int tm = (tl + tr) / 2;
    return sum(v * 2, tl, tm, l, min(r, tm), letter)
           + sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, letter);
}

void update (int v, int tl, int tr, int pos, int letter) {
    if (tl == tr) {
        if (s[tl] - 'a' == letter)
            t[letter][v] = 1;
        else
            t[letter][v] = 0;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v * 2, tl, tm, pos, letter);
        else
            update(v * 2 + 1, tm + 1, tr, pos, letter);
        t[letter][v] = t[letter][v * 2] + t[letter][v * 2 + 1];
    }
}

void solve() {
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> s[i];

    int q;
    cin >> q;

    for (int letter = 0; letter < 26; ++letter)
        build(1, 0, n - 1, letter);

    while (q--) {
        int type;
        cin >> type;

        if (type == 1) {
            int a;
            char b;
            cin >> a >> b;
            --a;
            s[a] = b;

            for (int letter = 0; letter < 26; ++letter)
                update(1, 0, n - 1, a, letter);
        } else {
            int a;
            int b;
            cin >> a >> b;
            int answr = 0;
            --a;
            --b;

            for (int letter = 0; letter < 26; ++letter) {
                if (sum(1, 0, n - 1, a, b, letter) > 0)
                    ++answr;
            }

            cout << answr << "\n";
        }
    }
}

#endif


void multisolve() {
    int t;
    cin >> t;

    while (t--)
        solve();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

    precalc();

#ifdef multi
    multisolve();
#else
    solve();
#endif

#ifdef LOCAL
    //cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
}

Measured memory_bytes: 160000