from collections import defaultdict 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) def op(l, r): return (l[0] + r[0], min(l[0] + r[1], l[1] + r[4]), min(l[0] + r[2], l[1] + r[5], l[2] + r[7]), min(l[0] + r[3], l[1] + r[6], l[2] + r[8], l[3] + r[9]), l[4] + r[4], min(l[4] + r[5], l[5] + r[7]), min(l[4] + r[6], l[5] + r[8], l[6] + r[9]), l[7] + r[7], min(l[7] + r[8], l[8] + r[9]), l[9] + r[9]) e = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0) d = defaultdict(tuple) d['A'] = (0, 0, 0, 0, 1, 1, 1, 1, 1, 1) d['B'] = (1, 0, 0, 0, 0, 0, 0, 1, 1, 1) d['C'] = (1, 1, 0, 0, 1, 0, 0, 0, 0, 1) d['D'] = (1, 1, 1, 0, 1, 1, 0, 1, 0, 0) N, Q = map(int, input().split()) S = input() v = [d[i] for i in S] seg = SegTree(op, e, v) for _ in range(Q): t, a, b = input().split() if t == '1': a = int(a) - 1 seg.set(a, d[b]) else: a = int(a) - 1 b = int(b) - 1 print(seg.prod(a, b + 1)[3])