#include<bits/stdc++.h>
using namespace std;
#define data_type long long
class segment_tree
{

public:
    vector<vector<data_type>>tree,lazy;
    string str;
    vector<data_type> add(vector<data_type> a,vector<data_type>b)
    {
        vector<data_type>ans(26,0);
        for(int i=0; i<26; i++)
            {
                ans[i]=(a[i]|b[i]);
            }
        return ans;
    }

    void build(int p,int begin,int end)
    {
        if(begin==end)
            {
                vector<data_type>arr (26,0);
                arr[str[begin]-'a']=1;
                tree[p]=arr;
                return;
            }
        int left=p<<1;
        int right=(p<<1)+1;
        int mid=(begin+end)>>1;
        build(left,begin,mid);
        build(right,mid+1,end);
        tree[p]=add(tree[left],tree[right]);

    }


    void update(int p,int begin,int end,int l,int r,char value)
    {
        if(l>end || r<begin)
            return ;
        if(begin>=l && end<=r)
            {
                vector<data_type>arr (26,0);
                arr[value-'a']=1;
                tree[p]=arr;
                return;

            }
        int left=p<<1;
        int right=(p<<1)+1;
        int mid=(begin+end)>>1;
        update(left, begin, mid, l, r,value);
        update(right, mid+1, end, l, r,value);
        tree[p]=add(tree[left],tree[right]);

    }

    unordered_set<data_type> query(int p,int begin,int end,int l,int r)
    {
        unordered_set<data_type> ans,ans2;
        if(l>end || r<begin)
            return ans ;
        if (begin >= l && end <= r)
            {
                for(int i=0; i<26; i++)
                    if(tree[p][i])
                        ans.insert(i);
                return ans;
            }

        int left=p<<1;
        int right=(p<<1)+1;
        int mid=(begin+end)>>1;
        ans = query(left, begin,mid,l,r);
        ans2= query(right, mid+1,end,l,r);
        ans.insert(ans2.begin(),ans2.end());
        return ans;

    }
    void print(int p, int begin, int end)
    {
        cout<<"--->"<<p<<" "<<begin<<" "<<end<<" "<<endl;
        for(auto i:tree[p])
            cout<<i<<" ";
        cout<<endl;
        if (begin==end)
            return;
        int mid = (begin+end)>>1;
        print(p<<1, begin, mid);
        print((p<<1)+1, mid+1, end);
    }
    segment_tree(string temp)
    {
        str=temp;
        tree.resize(4*str.size());
        build(1,0,str.size()-1);
    }
    data_type rmq(int i,int j)
    {
        unordered_set<data_type> a=query(1,0,str.size()-1,i,j);
        return a.size();
    }
    void update(int i,int j,char value)
    {
        update(1,0,str.size()-1,i,j,value);
    }
};
int main()
{
    int n,q;
    cin>>n;
    string str;
    cin>>str;
    segment_tree st(str);
    cin>>q;
    while(q--)
        {
            int x,a,b;
            char ch;
            cin>>x;
            if(x==1)
                {
                    cin>>a>>ch;
                    a--;
                    st.update(a,a,ch);
                }
            else
                {
                    cin>>a>>b;
                    a--,b--;
                    cout<< st.rmq(a,b)<<endl;;
                }
        }



    return 0;
}


Measured memory_bytes: 268932