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

using S = array<array<int,4>,4>;
constexpr S e(){ return S(); }
S op(S lhs, S rhs){
    S tmp = e();
    for(int i = 0; i < 4; i++){
        for(int j = i; j < 4; j++){
            for(int k = j; k < 4; k++){
                tmp[i][k] = max(tmp[i][k], lhs[i][j] + rhs[j][k]);
            }
        }
    }
    return tmp;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, Q;
    string s;
    cin >> n >> Q >> s;
    array<S, 4> tb{{}};
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 4; j++){
            for(int k = j; k < 4; k++){
                tb[i][j][k] = j <= i && i <= k;
            }
        }
    }
    vector<S> tmp(n);
    for(int i = 0; i < n; i++) tmp[i] = tb[s[i] - 'A'];
    atcoder::segtree<S, op, e> seg(tmp);
    while(Q--){
        int cmd;
        cin >> cmd;
        if(cmd == 1){
            int x;
            char c;
            cin >> x >> c;
            seg.set(x - 1, tb[c - 'A']);
        }else{
            int l, r, mx = 0;
            cin >> l >> r;
            l--;
            auto A = seg.prod(l, r);
            for(int i = 0; i < 4; i++){
                for(int j = i; j < 4; j++){
                    mx = max(mx, A[i][j]);
                }
            }
            cout << r - l - mx << '\n';
        }
    }
}