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 N,Q = map(int, input().split()) S = input() alp = {"A":0,"B":1,"C":2,"D":3} da = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1] db = [1, 0, 0, 0, 0, 0, 0, 1, 1, 1] dc = [1, 1, 0, 0, 1, 0, 0, 0, 0, 1] dd = [1, 1, 1, 0, 1, 1, 0, 1, 0, 0] p = [0,3,5,6] D = [] for i in S: if i == "A": D.append(da) elif i == "B": D.append(db) elif i == "C": D.append(dc) else: D.append(dd) def op(X,Y): res = [inf]*10 for i in range(4): for j in range(i,4): for k in range(i,j+1): res[p[i]+j] = min(X[p[i]+k]+Y[p[k]+j],res[p[i]+j]) return res e = [0]*10 st = SegTree(op, e, D) ans = [] for _ in range(Q): t,x,c = input().split() if t == "1": x = int(x)-1 if c == "A": st.set(x,da) elif c == "B": st.set(x,db) elif c == "C": st.set(x,dc) else: st.set(x,dd) else: x,c = int(x)-1,int(c) res = st.prod(x,c) ans.append(min(res)) print(*ans, sep = "\n")