/*********************************************************************
--------------------------------------------------------------------
--------------------------------------------------------------------
* Life is just a life. Lead it, Feel it & Enjoy It Properly.
* Nothing is impossible. Just believe in yourself & Almighty.
--------------------------------------------------------------------
--------------------------------------------------------------------
*********************************************************************/

#include<iostream>
using namespace std;
//---------------------Define Section--------------------------------
#define nl "\n"
#define tb "\t"
#define sp " "
#define eps 1e-7
#define ll long long
#define pi acos(-1.0)
//---------------------Input Section---------------------------------
#define si1(x)          scanf("%d",&x)
#define si2(x,y)        scanf("%d %d", &x, &y)
#define si3(x,y,z)      scanf("%d %d %d", &x, &y, &z)
#define sd1(x)          scanf("%lf",&x)
#define sd2(x,y)        scanf("%lf %lf", &x, &y)
#define sd3(x,y,z)      scanf("%lf %lf %lf", &x, &y, &z)
#define sli1(x)         scanf("%lld",&x)
#define sli2(x,y)       scanf("%lld %lld", &x, &y)
#define sli3(x,y,z)     scanf("%lld %lld %lld", &x, &y, &z)
//-------------------source code section------------------------------

//-------------------------- End -------------------------------------

//------------------------------  Segment Tree -------------------------------------------------

#define mt 500007
ll ArT[mt];
ll tree[mt*3];

ll MargeTree(ll LF,ll RF)
{
    return (LF|RF);
}

void Tree_creation(ll node, ll b, ll e)
{
    if(b==e)
    {
        tree[node]=ArT[b];
        return;
    }

    Tree_creation( node*2, b, (b+e)/2);
    Tree_creation( (node*2)+1, (((b+e)/2)+1), e);

    ll LF=tree[node*2];
    ll RF=tree[node*2+1];
    tree[node] = MargeTree(LF,RF);
}

void Tree_Update(ll node, ll b, ll e, ll pos, ll val)
{
    if(pos>e || pos<b)
    return;

    if(b==e)
    {
        tree[node]=val;
        return;
    }

    Tree_Update(node*2,b,(b+e)/2,pos,val);
    Tree_Update( (node*2)+1, (((b+e)/2)+1), e, pos, val);

    ll LF=tree[node*2];
    ll RF=tree[node*2+1];

    tree[node] = MargeTree(LF,RF);
}

ll Tree_Query(ll node, ll b, ll e, ll st, ll en)
{
    if(st>e || en<b)
        return 0;
    if(b>=st && e<=en)
        return tree[node];

    ll LF = Tree_Query( node*2, b, (b+e)/2 , st, en);
    ll RF = Tree_Query( (node*2)+1, (((b+e)/2)+1), e, st, en);

    return MargeTree(LF,RF);
}
//----------------------------------------------------------------

ll test;
void DenTofieM()
{
    cin >> test;

    for(ll i=1; i<=test; i++)
    {
        char p;
        cin >> p;
        ll k = p-97;
        ArT[i]=(1<<k);
    }

    //for(ll i=1; i<=test; i++) cout << ArT[i] << " ";

    Tree_creation(1,1,test);

    ll Q;
    cin >> Q;

    while(Q--)
    {
        ll n;
        cin >> n;

        if(n==1)
        {
            ll pos;
            char ch;
            cin >> pos >> ch;
            ll k = ch-97;
            k=(1<<k);
            Tree_Update(1,1,test,pos,k);
        }
        else if(n==2){
            ll l, r;
            cin >> l >> r;
            ll pk=Tree_Query(1,1,test,l,r);
            ll cnt=0;
            while(pk>0)
            {
                if(pk%2==1) cnt++;
                pk/=2;
            }
            cout << cnt << nl;
        }
    }
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);cout.tie(NULL);
    //freopen("hamming.in","r",stdin);

    DenTofieM();
    return 0;
}


Measured memory_bytes: 12544