#include <bits/stdc++.h>

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

template<typename T>
struct SegmentTree {
    int n;
    vector<T> sumv;

    void init(int n) {
        this->n = n;
        sumv.assign(2 * n - 1, 0);
    }

    template<typename ParameterType>
    void buildup(vector<ParameterType>& A) {
        n = A.size();
        sumv.assign(2 * n - 1, 0);
        for (int i = 0; i < n; i++)
            sumv[i + n - 1] = A[i];
        for (int i = n - 2; i >= 0; i--)
            sumv[i] = sumv[2 * i + 1] + sumv[2 * i + 2];
    }

    void add_value(int x, T val) {
        x += n -1;
        sumv[x] += val;
        while (x) {
            x = ((x - 1)>>1);
            sumv[x] = sumv[2 * x + 1] + sumv[2 * x + 2];
        }
    }

    void set_value(int x, T val) {
        x += n -1;
        sumv[x] = val;
        while (x) {
            x = ((x - 1)>>1);
            sumv[x] = sumv[2 * x + 1] + sumv[2 * x + 2];
        }
    }

    T query_sum_value(int x, int y) {
        x += n - 1;
        y += n - 1;
        T ans = 0;
        while (x <= y) {
            if (!(x & 1)) {
                ans += sumv[x++];
            } else if (y & 1) {
                ans += sumv[y--];
            } else {
                x = ((x - 1)>>1);
                y = ((y - 1)>>1);
            }
        }
        return ans;
    }

    T query_global_sum_value() {
        return sumv[0];
    }

    vector<T> unwind() {
        vector<T> A(n);
        for (int i = 0; i < n; i++)
            A[i] = query_sum_value(i, i);
        return A;
    }
};

vector<SegmentTree<int>> segment;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    string str;
    int q;
    cin >> n;
    cin >> str;
    segment.resize(26);
    for (int i = 0; i < 26; i++)
        segment[i].init(n);
    for (int i = 0; i < n; i++) {
        int c = str[i] - 'a';
        segment[c].set_value(i, 1);
    }
    cin >> q;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int a, b;
            char ch;
            cin >> b >> ch;
            b--;
            if (str[b] != ch) {
                a = str[b] - 'a';
                segment[a].set_value(b, 0);
                a = ch - 'a';
                segment[a].set_value(b, 1);
                str[b] = ch;
            }
        } else if  (t == 2) {
            int l, r;
            cin >> l >> r;
            l--, r--;
            int ans = 0;
            for (int i = 0; i < 26; i++) {
                if (segment[i].query_sum_value(l, r)) {
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }       

    return 0;
}


Measured memory_bytes: 104604