// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

template <typename T>
class segment_tree {
public:
    segment_tree(int n_) : n(__lowest_power_of_2(n_)), dat(n * 2, 0), lazy(n * 2, 0) {}

    template <typename Iterator>
    segment_tree(Iterator left, Iterator right)
        : n(__lowest_power_of_2(std::distance(left, right))), dat(n * 2, 0), lazy(n * 2, 0) {
        std::copy(left + n, right + n, dat.begin());
        for (int i = n - 1; i >= 1; --i) {
            dat[i] = std::max(dat[i * 2], dat[i * 2 + 1]);
        }
    }

private:
    int n;
    std::vector<T> dat, lazy;

public:
    void add(int ql, int qr, const T &x) { __add(1, 0, n, ql, qr, x); }

    T sum(int ql, int qr) { return __sum(1, 0, n, ql, qr); }

private:
    void __flush_lazy(int v, int l, int r) {
        dat[v] += lazy[v] * (r - l);
        if (v < n) {
            lazy[v * 2] += lazy[v];
            lazy[v * 2 + 1] += lazy[v];
        }
        lazy[v] = 0;
    }

    void __update_dat(int v) { dat[v] = dat[v * 2] + dat[v * 2 + 1]; }

    void __add(int n, int l, int r, const int ql, const int qr, const T &x) {
        __flush_lazy(n, l, r);
        if (r <= ql || qr <= l) {
            return;
        } else if (ql <= l && r <= qr) {
            lazy[n] += x;
            __flush_lazy(n, l, r);
        } else {
            int m = (l + r) / 2;
            __add(n * 2, l, m, ql, qr, x);
            __add(n * 2 + 1, m, r, ql, qr, x);
            __update_dat(n);
        }
    }

    T __sum(int n, int l, int r, const int ql, const int qr) {
        __flush_lazy(n, l, r);
        if (r <= ql || qr <= l) {
            return 0;
        } else if (ql <= l && r <= qr) {
            return dat[n];
        } else {
            int m = (l + r) / 2;
            T res_left = __sum(n * 2, l, m, ql, qr);
            T res_right = __sum(n * 2 + 1, m, r, ql, qr);
            __update_dat(n);
            return res_left + res_right;
        }
    }

    int __lowest_power_of_2(int x) const {
        int res = 1;
        while (res < x) res <<= 1;
        return res;
    }
};

int main(){	

	ll N, Q;
	string S;
	cin >> N;
	cin >> S;
	cin >> Q;
	vector<ll> q1(Q), q2(Q), q3(Q); 
	rep(i, Q) {
		cin >> q1[i] >> q2[i];
		if (q1[i] == 1) {
			char c;
			cin >> c;
			q3[i] = c-'a';
		} else {
			cin >> q3[i];
		}
	}

	
	vector< segment_tree<ll> > st(26, segment_tree<ll>(N));

	rep(i, N) {
		// cout << S[i]-'a' << endl;
		st[S[i]-'a'].add(i, i+1, 1);
	}

	rep(i, Q) {
		if (q1[i] == 1) {
			st[S[q2[i]-1]-'a'].add(q2[i]-1, q2[i], -1);
			S[q2[i]-1] = 'a'+q3[i];
			st[S[q2[i]-1]-'a'].add(q2[i]-1, q2[i], 1);
		} else {
			ll res = 0;
			rep(j, 26) {
				if (st[j].sum(q2[i]-1, q3[i]) > 0) {
					res++;
				}
			}
			cout << res << endl;
		} 
	}

	// st[0].add(0, 1, 1);
	// cout << st[0].sum(0, 2);
	// rep(i, N) {	
	// 	if ()
	// }
	
}


Measured memory_bytes: 443780