class SegTree: def __init__(self, op, e, lst): self.n = len(lst) self.N0 = 2 ** (self.n - 1).bit_length() self.op = op self.e = e self.data = [e] * (2 * self.N0) for i in range(self.n): self.data[self.N0 + i] = lst[i] for i in range(self.N0 - 1, 0, -1): self.data[i] = self.op(self.data[2*i], self.data[2*i+1]) def set(self, i, x): i += self.N0 self.data[i] = x while i > 1: i >>= 1 self.data[i] = self.op(self.data[2*i], self.data[2*i+1]) def prod(self, l, r): if r <= l: return self.e lres = self.e rres = self.e l += self.N0 r += self.N0 while l < r: if l & 1: lres = self.op(lres, self.data[l]) l += 1 if r & 1: r -= 1 rres = self.op(self.data[r], rres) l >>= 1 r >>= 1 return self.op(lres, rres) import sys input = sys.stdin.readline inf = 10**6 size = 4 N,Q = map(int, input().split()) S = input() alp = {"A":0,"B":1,"C":2,"D":3} def make_matrix(c): x = alp[c] A = [inf]*16 for i in range(4): for j in range(i,4): if i <= x <= j: A[i*size+j] = 0 else: A[i*size+j] = 1 return A D = [] for i in range(N): D.append(make_matrix(S[i])) def op(X,Y): res = [inf]*16 for i in range(4): for j in range(i,4): for k in range(i,j+1): res[i*size+j] = min(X[i*size+k]+Y[k*size+j], res[i*size+j]) return res e = [0]*16 st = SegTree(op, e, D) for _ in range(Q): t,x,c = input().split() if t == "1": x = int(x)-1 st.set(x,make_matrix(c)) else: l,r = int(x)-1,int(c) res = st.prod(l,r) print(min(res))