INF = 10 ** 9 def e(): return (0, 0, 0, 0, 0, 0, 0, 0, 0, 0) def op(a, b): a00, a01, a02, a03, a11, a12, a13, a22, a23, a33 = a b00, b01, b02, b03, b11, b12, b13, b22, b23, b33 = b return ( a00 + b00, min(a00 + b01, a01 + b11), min(a00 + b02, a01 + b12, a02 + b22), min(a00 + b03, a01 + b13, a02 + b23, a03 + b33), a11 + b11, min(a11 + b12, a12 + b22), min(a11 + b13, a12 + b23, a13 + b33), a22 + b22, min(a22 + b23, a23 + b33), a33 + b33 ) c2mat = [ (0,0,0,0,1,1,1,1,1,1), (1,0,0,0,0,0,0,1,1,1), (1,1,0,0,1,0,0,0,0,1), (1,1,1,0,1,1,0,1,0,0) ] def solve(): n, q = map(int, input().split()) s = [ord(c) - 65 for c in input()] lg = (n - 1).bit_length() sz = 1 << lg d = [(1,) * 10] * (2 * sz) for i in range(n): d[sz + i] = c2mat[s[i]] for i in range(sz - 1, 0, -1): d[i] = op(d[i<<1], d[i<<1|1]) for _ in range(q): t, x, c = input().split() if t == '1': x = sz + int(x) - 1 c = ord(c) - 65 d[x] = c2mat[c] x >>= 1 while x: d[x] = op(d[x<<1], d[x<<1|1]) x >>= 1 else: l = sz + int(x) - 1 r = sz + int(c) sl = e() sr = e() while l < r: if l & 1: sl = op(sl, d[l]) l += 1 if r & 1: r -= 1 sr = op(d[r], sr) l >>= 1 r >>= 1 print(op(sl, sr)[3]) solve()