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

S = eval(input())

items = []

for i in range(Q):

    items.append(tuple(map(int, input().split())))



from itertools import accumulate



prev = ""

acc = [0] * N

for i, s in enumerate(S):

    if s == "C" and prev == "A":

        acc[i] = 1

    prev = s





acc = list(accumulate(acc))

ans = []

for i in range(Q):

    l, r = items[i]



    ans.append(acc[r -1] - acc[l-1])

for a in ans:

    print(a)

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

S = eval(input())

items = []

for i in range(Q):

    items.append(tuple(map(int, input().split())))



acc = [0] * N

for i in range(1, N):

    if S[i] == "C" and S[i-1] == "A":

        acc[i] += 1

from itertools import accumulate

acc = list(accumulate(acc))



for l, r in items:

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

N, Q = list(map(int, input().split()))
S = eval(input())
items = []
for i in range(Q):
    items.append(tuple(map(int, input().split())))
from itertools import accumulate

prev = ""
acc = [0] * N
for i, s in enumerate(S):
    if s == "C" and prev == "A":
        acc[i] = 1
    prev = s
acc = list(accumulate(acc))
ans = []
for i in range(Q):
    l, r = items[i]
    ans.append(acc[r - 1] - acc[l - 1])
for a in ans:
    print(a)

N, Q = list(map(int, input().split()))
S = eval(input())
items = []
for i in range(Q):
    items.append(tuple(map(int, input().split())))
acc = [0] * N
for i in range(1, N):
    if S[i] == "C" and S[i - 1] == "A":
        acc[i] += 1
from itertools import accumulate

acc = list(accumulate(acc))
for l, r in items:
    print((acc[r - 1] - acc[l - 1]))

+acc = [0] * N +for i in range(1, N): +    if S[i] == "C" and S[i - 1] == "A": +        acc[i] += 1 -prev = "" -acc = [0] * N -for i, s in enumerate(S): -    if s == "C" and prev == "A": -        acc[i] = 1 -    prev = s -ans = [] -for i in range(Q): -    l, r = items[i] -    ans.append(acc[r - 1] - acc[l - 1]) -for a in ans: -    print(a) +for l, r in items: +    print((acc[r - 1] - acc[l - 1]))