#include using namespace std; #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define ov4(a, b, c, d, name, ...) name #define rep3(i, a, b, c) for (int i = (a); i < (b); i += (c)) #define rep2(i, a, b) rep3(i, a, b, 1) #define rep1(i, n) rep2(i, 0, n) #define rep0(n) rep1(aaaaaa, n) #define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__) #define per(i, a, b) for(int i = (a)-1; i >= (b); i--) #define fore(e, v) for (auto&& e : v) #define lb(v, x) (lower_bound(all(v), x)- begin(v)); #define eb emplace_back using ll = long long; using vi = vector; using vl = vector; using pii = pair; using pll = pair; using ld = double; template bool chmin(T& a, const S& b) {return a > b ? a = b, 1 : 0; } template bool chmax(T& a, const S& b) {return a < b ? a = b, 1 : 0; } vector dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; const int INF = 1e9 + 100; const ll linf = 1e18 + 100; int clamp(int l, int r, int x) {return min(max(l, x), r);} template struct segtree { segtree(int n) : segtree(vector(n, e())) {} segtree(const vector& v) : n(sz(v)) { s = bit_ceil(unsigned(n)); log = countr_zero(unsigned(s)); d = vector(2 * s, e()); rep(i, n) d[s + i] = v[i]; per(i, s, 1) update(i); } void set(int p, S x) { d[p += s] = x; rep(i, 1, log + 1) update(p >> i); } S prod(int l, int r) const { S sml = e(), smr = e(); l += s, r += s; while(l < r) { if(l & 1) sml = op(sml, d[l++]); if(r & 1) smr = op(d[--r], smr); l >>= 1, r >>= 1; } return op(sml, smr); } S all_prod() const { return d[1]; } template int max_right(int l, F f) const { if(l == n) return n; l += s; S sm = e(); do { while(~l & 1) l >>= 1; if(!f(op(sm, d[l]))) { while(l < s) { l <<= 1; if(f(op(sm, d[l]))) sm = op(sm, d[l++]); } return l - s; } sm = op(sm, d[l++]); } while((l & -l) != l); return n; } template int min_left(int r, F f) const { if(!r) return 0; r += s; S sm = e(); do { r--; while(r > 1 and r & 1) r >>= 1; if(!f(op(d[r], sm))) { while(r < s) { r = (2 * r + 1); if(f(op(d[r], sm))) sm = op(d[r--], sm); } return r + 1 - s; } sm = op(d[r], sm); } while((r & -r) != r); return 0; } private: int n, s, log; vector d; void update(int k) { d[k] = op(d[k * 2], d[k * 2 + 1]); } }; const int iinf = 1e9 + 100; using S = array; const int m = 4; int idx(int l, int r){ return l * (m + 1) + r; } void print(S x) { rep(l, m+1) { rep(r, l+1, m+1) cout << x[idx(l, r)] << " "; cout << endl; } } S e() { return S{}; } S op(S x, S y) { S z = e(); rep(l, m)rep(r, l+1, m+1)z[idx(l, r)] = iinf; rep(l, m+1)rep(r, l+1, m+1)rep(k, l, r) { chmin(z[idx(l, r)], x[idx(l, k+1)] + y[idx(k, r)]); } return z; } void solve() { int n, q;cin >> n >> q; string s;cin >> s; auto item = [&](int x) -> S { S z = e(); rep(l, m)rep(r, l+1, m+1)z[idx(l, r)] = iinf; rep(l, m)rep(r, l+1, m+1) { if (x < l) z[idx(l, r)] = 1; else if (x >= r) z[idx(l, r)] = 1; else z[idx(l, r)] = 0; } return z; }; vector v(n); rep(i, n) v[i] = item(s[i] - 'A'); segtree st(v); rep(q) { int t;cin >> t; if (t == 1) { int x;cin >> x;x--; char c;cin >> c; st.set(x, item(c - 'A')); } else { int l, r;cin >> l >> r; l--; // print(st.prod(l, r)); cout << st.prod(l, r)[idx(0, m)] << endl; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); // int T;cin >> T; int T = 1; while (T--) { solve(); } }