#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
template<typename T, typename E, typename F, typename G>
class SegmentTree {
    int N;
    F f;
    G g;
    T ti;
    vector<T> dat;

public:
    SegmentTree(int n, F f, G g, T ti) : N(1), f(f), g(g), ti(ti) {
        while (N < n) {
            N <<= 1;
        }
        dat.resize(2 * N - 1, ti);
    }

    void build(int n, vector<T> v) {
        for (int i = 0; i < n; ++i) {
            dat[i + N - 1] = v[i];
        }
        for (int i = N - 2; i >= 0; --i) {
            dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    void update(int k, T t) {
        k += N - 1;
        dat[k] = g(dat[k], t);
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return ti;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            T left = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T right = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return f(left, right);
        }
    }

    T query(int a, int b) {
        return query(a, b, 0, 0, N);
    }

};

class Solve {
public:
    void solve() {
        Int N, Q;
        string s;
        cin >> N >> s >> Q;

        using T = Int;
        using E = Int;
        T ti = 0;
        auto f = [](T a, T b) -> T {
            return a | b;
        };
        auto g = [](T a, E b) -> T {
            return b;
        };

        SegmentTree<T, E, decltype(f), decltype(g)> treeone(N, f, g, ti);
        for (int i = 0; i < N; ++i) {
            treeone.update(i, 1 << (s[i] - 'a'));
        }

        while (Q--) {
            Int e;
            cin >> e;
            if (e == 1) {
                Int i;
                char c;
                cin >> i >> c;
                treeone.update(i - 1, 1 << (c - 'a'));
            } else {
                Int l, r;
                cin >> l >> r;
                l--;
                Int tmp = treeone.query(l, r);
                Int ans = __pop_count((unsigned) tmp);
                cout << ans << endl;
            }
        }


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 9080