#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WmarkNINGS
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define M2 998244353
#define ll long long
#define pll pair<long, long>
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define ff first
#define ss second
#define pb push_back
#define db pop_back
#define mp make_pair
#define mt make_tuple
#define g(a, b) get<a>(b)
#define INF (ll)1e18 + 100
#define vl vector<ll>
#define vi vector<int>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define all(v) v.begin(), v.end()
#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[], ll b[], ll n);
ll logint(ll x, ll y);

ll gcd(ll x, ll y)
{
    if (x == 0)
        return y;
    return gcd(y % x, x);
}

ll powM(ll x, ll y, ll m)
{
    if (y == 0)
        return 1;
    ll p = powM(x, y / 2, m) % m;
    p = (p * p) % m;
    return (y % 2 == 0) ? p : (x * p) % m;
}

/*ll modI(ll a, ll m)
{
   return powM(a, m-2, m);
}*/
ll modI(ll a, ll m)
{
    ll m0 = m, y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}
void pairsort(int a[], int b[], int n)
{
    pair<int, int> v[n];
    REP(i, 0, n)
    {
        v[i].ff = a[i];
        v[i].ss = b[i];
    }
    sort(v, v + n);
    REP(i, 0, n)
    {
        a[i] = v[i].ff;
        b[i] = v[i].ss;
    }
}

void pairsortll(ll a[], ll b[], ll n)
{
    pair<ll, ll> v[n];
    REP(i, 0, n)
    {
        v[i].ff = a[i];
        v[i].ss = b[i];
    }
    sort(v, v + n);
    REP(i, 0, n)
    {
        a[i] = v[i].ff;
        b[i] = v[i].ss;
    }
}

ll logint(ll x, ll y)
{
    ll ans = 0;
    ll a = 1;
    for (ll i = 0; i <= x; i++)
    {
        if (x < a)
        {
            return ans;
        }
        ans++;
        a *= y;
    }
    return -1;
}

set<int>seg[4*(int)5e5 + 1];
ll n;
string s;
void build(int node, int start, int end){
    if(start == end){
        seg[node].insert(s[start]-'a');
    }
    else
    {
        int mid = (start + end) / 2;
        // Recurse on the left child
        build(2*node, start, mid);
        // Recurse on the right child
        build(2*node+1, mid+1, end);
        // Internal node will have the sum of both of its children
        for(auto y:seg[2*node]){
            seg[node].insert(y);
        }
        for(auto y:seg[2*node+1]){
            seg[node].insert(y);
        }
    }
}
void update(int node, int start, int end, int idx, int val)
{
    if(start == end)
    {
        seg[node].clear();
        seg[node].insert(val);
    }
    else
    {
        int mid = (start + end) / 2;
        if(start <= idx && idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update(2*node, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update(2*node+1, mid+1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        seg[node].clear();
        for(auto y:seg[2*node]){
            seg[node].insert(y);
        }
        for(auto y:seg[2*node+1]){
            seg[node].insert(y);
        }
    }
}

set<int> query(int node, int start, int end, int l, int r)
{
    set<int>z;
    if(r < start || end < l)
    {
        // range represented by a node is completely outside the given range
        return z;
    }
    if(l <= start && end <= r)
    {
        // range represented by a node is completely inside the given range
        return seg[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    set<int>p1 = query(2*node, start, mid, l, r);
    set<int>p2 = query(2*node+1, mid+1, end, l, r);
    for(auto y:p1){
        z.insert(y);
    }
    for(auto y:p2){
        z.insert(y);
    }
    return z;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //clock_t begin = clock();
    cin>>n>>s;
    ll q;
    cin>>q;
    build(1,0,n-1);
        while(q--){
        ll a, b;
        cin>>a>>b;
        if(a == 1){
            char c;
            cin>>c;
            update(1,0,n-1,b-1,c-'a');
        }
        else{
            ll c;
            cin>>c;
            cout<<query(1,0,n-1,b-1,c-1).size()<<"\n";
        }
    }
}



Measured memory_bytes: 233756