class SegTree: def __init__(self, op, e, lst): if type(lst) is int: self.n = lst else: 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 update(self, i, x): #a_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 add(self, i, x): i += self.N0 self.data[i] = self.op(x, self.data[i]) while i > 1: i >>= 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) inf = 1<<60 N,Q = map(int, input().split()) S = input() def make_matrix(c): x = ord(c) - ord("A") A = [[inf]*4 for i in range(4)] for i in range(4): for j in range(i,4): if i <= x <= j: A[i][j] = 0 else: A[i][j] = 1 return A D = [] for i in range(N): D.append(make_matrix(S[i])) def op(X,Y): res = [[inf]*4 for i in range(4)] for i in range(4): for j in range(i,4): for k in range(i,j+1): res[i][j] = min(X[i][k]+Y[k][j], res[i][j]) return res e = [[0]*4 for i in range(4)] 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) ans = inf for i in range(4): ans = min(ans,min(res[i])) print(ans)