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) if type(lst) is list: 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 get(self, i): return self.data[self.N0+i] 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} D = [] for i in range(N): c = alp[S[i]] A = [inf]*16 for i in range(4): for j in range(i,4): if i <= c <= j: A[i*size+j] = 0 else: A[i*size+j] = 1 D.append(A) 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) qry = [] for _ in range(Q): t,x,c = input().split() t = int(t) x = int(x)-1 if t == 1: c = alp[c] else: c = int(c) qry.append((t,x,c)) ans = [] for t,x,c in qry: if t == 1: A = [inf]*16 for i in range(4): for j in range(i,4): if i <= c <= j: A[i*size+j] = 0 else: A[i*size+j] = 1 st.set(x,A) else: res = st.prod(x,c) ans.append(min(res)) print(*ans, sep = "\n")