from atcoder import segtree N,Q=map(int,input().split()) S=input() S=list(S) """ a b c d ab bc cd da abc bcd d """ change = [] for i in range(4): for j in range(4): if j + i < 4: change.append((j,j+i)) move = [] for k in range(len(change)): for t in range(len(change)): if change[k][1] <= change[t][0]: new = (change[k][0],change[t][1]) move.append((k,t,change.index(new))) s = "ABCD" def one(n): count = 0 res = [] for i in range(4): for j in range(4): if j + i < 4: count += 1 if j <= n <= j+i: res.append(0) else: res.append(1) return tuple(res) def op(a,b): new = [10**10 for _ in range(10)] for a_,b_,c in move: new[c] =min(new[c], a[a_]+b[b_]) return tuple(new) st = segtree.SegTree(op=lambda a,b:op(a,b),e=tuple(0 for _ in range(10)),v=[one(s.index(S[i])) for i in range(N)]) for _ in range(Q): q=list(map(str,input().split())) if q[0] == "1": _,x,c = q x=int(x) st.set(x-1,one(s.index(c))) else: _,l,r = q l=int(l) r=int(r) ans=st.prod(l-1,r) print(min(ans))