#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
#include <bitset>
#include <cstdint>
#include <stdexcept>
using namespace std;

#pragma region Lib

// 整数型

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

// [0,n)を昇順/降順でループ

#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)

// [a,b)を昇順/降順でループ

#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)

// デバッグ

#ifdef DEBUG
#include <cassert>
#define my_assert(x) assert(x)
#else
#define my_assert(x)
#define assert(x)
#endif

#pragma endregion

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

struct int_gp
{
    using T = int;
    static constexpr T op(T a, T b)
    {
        return a + b;
    }
    static constexpr T opinv(T a, T b)
    {
        return a - b;
    }
    static inline constexpr T id = 0;
};

template <typename M>
struct fenwick_tree
{
    using T = typename M::T;

private:
    int n;
    vector<T> data;

public:
    // data[0] は使わない
    fenwick_tree(int size) : n(size), data(size + 1, M::id) {}

    int size()
    {
        return n;
    }

    // i番目にaを足す
    void add(int i, T a)
    {
        ++i;
        while (i <= n)
        {
            data[i] = M::op(data[i], a);
            i += i & -i;
        }
    }

    // T = int, op = operator + の場合
    void inline incr(int i)
    {
        add(i, 1);
    }
    void inline decr(int i)
    {
        add(i, -1);
    }

    // [0,i)の和 (0 <= i <= n)
    T sum0(int i)
    {
        T ret = M::id;
        while (i >= 1)
        {
            ret = M::op(ret, data[i]);
            i -= i & -i;
        }
        return ret;
    }

    // [l,r)の和 (0 <= l <= r <= n)
    T sum(int l, int r)
    {
        return M::opinv(sum0(r), sum0(l));
    }
};

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // 浮動小数の表示の精度
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<fenwick_tree<int_gp>> occ(26, fenwick_tree<int_gp>(n));
    rep(i, n)
    {
        int c = s[i] - 'a';
        occ[c].incr(i);
    }

    int q;
    cin >> q;
    rep(i_q, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int i;
            char ch;
            cin >> i >> ch;
            --i;
            int old_c = s[i] - 'a', c = ch - 'a';
            s[i] = ch;
            occ[old_c].decr(i);
            occ[c].incr(i);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            --l;
            int ans = 0;
            rep(c, 26)
            {
                if (occ[c].sum(l, r) > 0)
                {
                    ++ans;
                }
            }
            cout << ans << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 56552