/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/

#include<bits/stdc++.h>
#define pll              pair<long,long>
#define pii              pair<int,int>
#define scn(a)           scanf("%d", &a)
#define scn2(a, b)       scanf("%d%d", &a, &b)
#define scn3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pairl            pair<ll , ll >
#define scnl(a)          scanf("%lld", &a)
#define scnl2(a, b)      scanf("%lld%lld", &a, &b)
#define scnl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define scns(s)          scanf("%s",s)
#define prts(s)          printf("%s\n",s)
#define prt(a)           printf("%d\n", a)
#define prtl(a)          printf("%lld\n", a)
#define prs(a)           printf("%d ", a)
#define prt2(a, b)       printf("%d %d\n", a, b)
#define prt3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)          printf("%lld ", a)
#define prtl2(a, b)      printf("%lld %lld\n", a, b)
#define prtl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define ptcs(a)          printf("Case %d: ", a)
#define pf               printf
#define sc               scanf
#define vi               vector<int >
#define vil              vector<ll >
#define pb               push_back
#define mem(a, b)        memset((a), (b), sizeof(a))
#define lg2(n)           (31-__builtin_clz(n))
#define inf              9999999
#define ll               long long
#define ull              unsigned long long
#define MIN              INT_MIN
#define MAX              INT_MAX
#define fast             ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type, less<int >, rb_tree_tag, tree_order_statistics_node_update> odrst;
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
//___________________________________________________________________________________________________________________
const int N = 2e5 + 9;
const int mod = 1e9 + 7;
ll t,x,n,m,y,z,x1,x2,x3,x4,k,q;
odrst st[26];
string s;
char c;
int main()
{
    fast;
    cin>>n>>s;
    for(int i=1;i<=n;i++)
    {
        st[(int)(s[i-1]-'a')].insert(i);
    }
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>x;
        if(x==1)
        {
            cin>>x>>c;
            for(int j=0;j<26;j++)
            {
                x1=st[j].order_of_key(x);
                x2=*st[j].find_by_order(x1);
                if(x2==x)
                {
                    st[j].erase(x);
                    break;
                }
            }
            y=(int)(c-'a');
            st[y].insert(x);
        }
        else
        {
            int cn=0;
            cin>>x>>y;
            for(int j=0;j<26;j++)
            {
                x1=st[j].order_of_key(x);
                x2=st[j].order_of_key(y);
                x3=*st[j].find_by_order(x1);
                x4=*st[j].find_by_order(x2);
                if(x3!=x && x4!=y && x1==x2) continue;
                cn++;
            }
            cout<<cn<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24220