#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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

class SegmentTreeCnt{
    int n;
    vector<int> dat;
public:
    SegmentTreeCnt(){}
    SegmentTreeCnt(int m, int fill){
        int i = 1;
        while(i < m) i *= 2;
        n = i;
        dat.resize(2*i - 1);
        REP(j, 2*i-1) dat[j] = fill;
    }

    void update(int k, int a){
        k += n - 1;
        int moto = dat[k];
        dat[k] = a;
        while(k){
            k = (k - 1) / 2;
            dat[k] += a - moto;
        }
    }

    void updateIncrease(int k, int a){
        update(k, dat[k+n-1] + a);
    }
    void updateIncrease(int k){
        updateIncrease(k, 1);
    }

    void updateDecrease(int k, int a){
        update(k, dat[k+n-1] - a);
    }
    void updateDecrease(int k){
        updateDecrease(k, 1);
    }

    int getNum(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return dat[k];

        int vl = getNum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getNum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }

    int getvalue(int k){
        return dat[k+n-1];
    }

    bool getExist(int l, int r){
        return (getNum(l, r) > 0);
    }
};

int main(){
    int N, Q, a;
    string S;
    cin >> N >> S >> Q;
    vector<SegmentTreeCnt> ST(26);
    REP(i, 26) ST[i] = SegmentTreeCnt(N, 0);
    REP(i, N){
        int b = S[i] - 'a';
        ST[b].update(i, ST[b].getvalue(i) + 1);
    }
    REP(ik, Q){
        cin >> a;
        if(a == 1){
            int i; char c;
            cin >> i >> c;
            --i;
            int cc = c - 'a';
            int moto = S[i] - 'a';
            ST[cc].updateIncrease(i);
            ST[moto].updateDecrease(i);
            S[i] = c;
        }
        else{
            int l, r;
            cin >> l >> r;
            --l; --r;
            int cnt = 0;
            REP(j, 26){
                if(ST[j].getExist(l, r+1)) ++cnt; 
            }
            cout << cnt << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 107524