#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int n;
vector<char> s;
VVL seg;

void init(int node, int l, int r){
    //cerr<<node<<" "<<l<<" "<<r<<endl;
    
    if(node >= n-1){
        seg[node][s[node-(n-1)]]++;
        return;
    }

    int m = (l+r)/2;

    init(node*2+1, l,m);
    init(node*2+2, m,r);
    REP(i,26){
        seg[node][i] = seg[node*2+1][i] + seg[node*2+2][i];
    }

    return;
}

void update(int node, int befor, int after){
    seg[node][befor]--;
    seg[node][after]++;

    if(node == 0){
        return;
    }

    update((node-1)/2, befor, after);
    return;
}

VL segsearch(int node, int l, int r, int nl, int nr){
    //cerr<<node<<" "<<nl<<" "<<nr<<endl;
    //if(node>=0){
    //    cerr<<node<<" "<<nl<<" "<<nr<<endl;
    //}
    
    if(r <= nl || nr <= l){
        VL t(26);
        return t;
    }


    if(l <= nl && nr <= r){
        return seg[node];
    }

    int m = (nl+nr)/2;
    VL t1 = segsearch(node*2+1, l, r, nl, m);
    VL t2 = segsearch(node*2+2, l, r, m, nr);
    VL result(26);
    REP(i,26){
        result[i] = t1[i]+t2[i];
    }
    return result;

}

void Main()
{
    cin>>n;
    int n1=n;
    for(int i=1;;i*=2){
        if(i==n){
            break;
        }
        if(i>n){
            n=i;
            break;
        }
    }
    //cerr<<n<<endl;;

    s.resize(n);
    REP(i,n1){
        cin>>s[i];
        s[i] -= 'a';
    }
    int q;cin>>q;

    seg.resize(n*2);
    REP(i,n*2){
        seg[i].resize(26);
    }

    init(0, 0, n);

    REP(i,q){
        int type;cin>>type;
        if(type==1){
            int idx;cin>>idx;
            char c;cin>>c;
            idx--;
            c-='a';

            if(s[idx] == c){
                continue;
            }
            update(idx+n-1, s[idx], c);
            s[idx] = c;
        }
        else{
            int l,r;cin>>l>>r;
            l--;
            //r--;
            VL result = segsearch(0, l, r, 0, n);
            LL count = 0;
            REP(j,26){
                if(result[j] != 0){
                    count++;
                    //cerr<<char(j+'a');
                }
            }
            //cerr<<endl;
            std::cout<<count<<endl;
        }
        //REP(i,n1){
        //    cerr<<char(s[i]+'a');
        //}
        //cerr<<endl;
    }
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	std::cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 254848