//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
//#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
int n, q;
string str;
int t[4*5*100*1000];
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> str >> q;
}

void build(int v, int l, int r){
    if(l == r)
        t[v] = 1 << (str[l]-'a');
    else{
        int m = (l+r)/2;
        build(v*2, l, m);
        build(v*2+1, m+1, r);
        t[v] = t[v*2] | t[v*2+1];
    }
}

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

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

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    build(1, 0, n-1);
    while(q--){
        int tp;
        cin >> tp;
        if(tp == 1){
            int ind;
            char val;
            cin >> ind >> val;
            ind--;
            update(1, 0, n-1, ind, val);
        }else{
            int l, r;
            cin >> l >> r;
            cout << bitcount(get(1, 0, n-1, l-1, r-1)) << endl;
        }
    }

}

Measured memory_bytes: 7196