import numpy as np

n, q = list(map(int, input().split()))

s = eval(input())

w = np.zeros(n, dtype=int)



a = 0

for i in range(n):

    if s[i] == "A":

        if a == 0:

            a += 1

    elif s[i] == "C":

        if a:

            w[i-1] = 1

            a -= 1

    else:

        if a:

            a -= 1



ans = np.append(np.zeros(1, dtype=int), np.cumsum(w))

for _ in range(q):

    l, r = list(map(int, input().split()))

    print((ans[r-1] - ans[l-1]))

N, Q = list(map(int, input().split()))

S = eval(input())

t=[0]*(N+1)



for i in range(N):

    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)

for i in range(Q):

    l, r = list(map(int, input().split()))

    print((t[r-1] - t[l-1]))
import numpy as np

n, q = list(map(int, input().split()))
s = eval(input())
w = np.zeros(n, dtype=int)
a = 0
for i in range(n):
    if s[i] == "A":
        if a == 0:
            a += 1
    elif s[i] == "C":
        if a:
            w[i - 1] = 1
            a -= 1
    else:
        if a:
            a -= 1
ans = np.append(np.zeros(1, dtype=int), np.cumsum(w))
for _ in range(q):
    l, r = list(map(int, input().split()))
    print((ans[r - 1] - ans[l - 1]))

N, Q = list(map(int, input().split()))
S = eval(input())
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == "AC" else 0)
for i in range(Q):
    l, r = list(map(int, input().split()))
    print((t[r - 1] - t[l - 1]))

-import numpy as np - -n, q = list(map(int, input().split())) -s = eval(input()) -w = np.zeros(n, dtype=int) -a = 0 -for i in range(n): -    if s[i] == "A": -        if a == 0: -            a += 1 -    elif s[i] == "C": -        if a: -            w[i - 1] = 1 -            a -= 1 -    else: -        if a: -            a -= 1 -ans = np.append(np.zeros(1, dtype=int), np.cumsum(w)) -for _ in range(q): +N, Q = list(map(int, input().split())) +S = eval(input()) +t = [0] * (N + 1) +for i in range(N): +    t[i + 1] = t[i] + (1 if S[i : i + 2] == "AC" else 0) +for i in range(Q): -    print((ans[r - 1] - ans[l - 1])) +    print((t[r - 1] - t[l - 1]))