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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

class SegmentTree {
private:
    typedef tuple<int, int, int> int3;
    int N;
    vector<int> v;
    vector<int3> heap;

    int init(int l, int r, int i) {
        if(l == r) {
            return 0;
        }
        if(r - l == 1) {
            int value = v[l];
            heap[i] = make_tuple(l, r, value);
            return value;
        }
        int value = init(l, (l + r)/2, i*2) + init((l + r)/2, r, i*2 + 1);
        heap[i] = make_tuple(l, r, value);
        return value;
    }

public:
    SegmentTree(){}

    SegmentTree(vector<int> s) {
        int n = s.size();
        for(N = 1;N < n;N *= 2);
        heap.resize(2*N, make_tuple(0, 0, 0));
        v.resize(N, 0);
        copy(s.begin(), s.end(), v.begin());
        init(0, N, 1);
    }

    void update(int index, int value) {
        int l = 0;
        int r = N;
        int i = 1;
        for(;1 < r - l;) {
            int mid = (l + r)/2;
            if(index < mid) {
                r = mid;
                i *= 2;
            }else{
                l = mid;
                i = i*2 + 1;
            }
        }
        heap[i] = make_tuple(l, r, value);

        for(i /= 2;0 < i;i /= 2) {
            int l = get<0>(heap[i]);
            int r = get<1>(heap[i]);
            int v = get<2>(heap[i*2]) + get<2>(heap[i*2 + 1]);
            heap[i] = make_tuple(l, r, v);
        }
    }

    int segment(int l, int r, int i=1) {
        int left = get<0>(heap[i]);
        int right = get<1>(heap[i]);
        int mid = (left + right)/2;
        int value = get<2>(heap[i]);

        if(l == r) {
            return 0;
        }
        if(left == right) {
            return 0;
        }
        if(left == l && right == r) {
            return value;
        }
        if(r < mid) {
            return segment(l, r, i*2);
        }
        if(mid < l) {
            return segment(l, r, i*2 + 1);
        }
        return segment(l, mid, i*2) + segment(mid, r, i*2 + 1);
    }

    void print() {
        FOR(i, 1, 2*N) {
            cout << "(" << get<0>(heap[i]) << " " << get<1>(heap[i]) << " " << get<2>(heap[i]) << ") ";

            int k = 0;
            for(int j = i + 1;0 < j;j /= 2) {
                k += j&1;
            }
            if(k == 1) {
                cout << endl;
            }
        }
    }
};

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    S = '.' + S;

    map<char, SegmentTree> trees;
    FOR(i, 'a', 'z' + 1) {
        vector<int> s(N + 1, 0);
        REP(j, N + 1) {
            s[j] = S[j] == i;
        }
        trees[i] = SegmentTree(s);
    }
    int Q;
    cin >> Q;
    REP(q, Q) {
        int t;
        cin >> t;
        if(t == 1) {
            int i;
            char c;
            cin >> i >> c;
            trees[S[i]].update(i, 0);
            S[i] = c;
            trees[c].update(i, 1);
        }else if(t == 2) {
            int l, r;
            cin >> l >> r;
            int res = 0;
            FOR(c, 'a', 'z' + 1) {
                res += trees[c].segment(l, r + 1) != 0;
            }
            cout << res << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 377808