#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
struct SegmentTree {
	private:
        using Func = function<T(T, T)>;

        int n;
        vector<T> node;

        T init_v;
        Func func;

    public:

        SegmentTree(vector<T> a, Func _func, T _init_v) {
            int sz = a.size();
            n = 1;
            init_v = _init_v;
            func = _func;
    
            while (n < sz) n <<= 1;
            node.resize(2 * n - 1, init_v);
            for (int i = 0; i < sz; i++) node[i + n - 1] = a[i];
            for (int i = n - 2; i >= 0; i--) node[i] = func(node[i * 2 + 1], node[i * 2 + 2]);
        }

        void update(int pos, T v) {
            int k = pos + n - 1;
            node[k] = v;
            while (k > 0) {
                k = (k - 1) / 2;
                node[k] = func(node[k * 2 + 1], node[k * 2 + 2]);
            }
        }

        T get(int pos) {
            int k = pos + n - 1;
            return node[k];
        }

        T query(int a, int b, int k = 0, int l = 0, int r = -1) {
            if (r < 0) r = n;
            if (r <= a || b <= l) return init_v;
            if (a <= l && r <= b) return node[k];
            T lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return func(lv, rv);
        }

        int size(){
            return n;
        }
};

bitset<26> func(bitset<26> a, bitset<26> b){
    return a | b;
}

int main(void){
    int N; cin >> N;
    string S; cin >> S;
    vector<bitset<26>> a(N);
    REP(i,N){
        bitset<26> b;
        b[S[i]-'a'] = 1;
        a[i] = b;
    }

    bitset<26> b;
    SegmentTree<bitset<26>> st(a, func, b);

    int Q; cin >> Q;
    REP(j,Q){
        int type; cin >> type;
        if(type==1){
            int i; char c; cin >> i >> c;
            i--;
            bitset<26> b;
            b[c-'a'] = 1;
            st.update(i,b);
        }
        else{
            int l,r; cin >> l >> r;
            l--; r--;
            bitset<26> b = st.query(l,r+1,0,0,st.size());
            cout << b.count() << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 16900