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

S = eval(input())



ans = [0] * N

for i in range(N-1):

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

        ans[i+1] += (ans[i] + 1)

    else:

        ans[i+1] = ans[i]



for _ in range(Q):

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

    print((ans[r-1] - ans[l-1]))
from bisect import bisect_left, bisect_right

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

s = eval(input())

lr = [list(map(int, input().split())) for _ in range(q)]



numbers = []

for i in range(n-1):

    if s[i]+s[i+1] == "AC":

        numbers.append(i+1)

for l,r in lr:

    x,y = bisect_left(numbers, l), bisect_right(numbers, r)

    if x==y: print((0))

    elif numbers[y-1]+1 <= r:print((y-x))

    else: print((y-x-1))
N, Q = list(map(int, input().split()))
S = eval(input())
ans = [0] * N
for i in range(N - 1):
    if S[i] == "A" and S[i + 1] == "C":
        ans[i + 1] += ans[i] + 1
    else:
        ans[i + 1] = ans[i]
for _ in range(Q):
    l, r = list(map(int, input().split()))
    print((ans[r - 1] - ans[l - 1]))

from bisect import bisect_left, bisect_right

n, q = list(map(int, input().split()))
s = eval(input())
lr = [list(map(int, input().split())) for _ in range(q)]
numbers = []
for i in range(n - 1):
    if s[i] + s[i + 1] == "AC":
        numbers.append(i + 1)
for l, r in lr:
    x, y = bisect_left(numbers, l), bisect_right(numbers, r)
    if x == y:
        print((0))
    elif numbers[y - 1] + 1 <= r:
        print((y - x))
    else:
        print((y - x - 1))

-N, Q = list(map(int, input().split())) -S = eval(input()) -ans = [0] * N -for i in range(N - 1): -    if S[i] == "A" and S[i + 1] == "C": -        ans[i + 1] += ans[i] + 1 +from bisect import bisect_left, bisect_right + +n, q = list(map(int, input().split())) +s = eval(input()) +lr = [list(map(int, input().split())) for _ in range(q)] +numbers = [] +for i in range(n - 1): +    if s[i] + s[i + 1] == "AC": +        numbers.append(i + 1) +for l, r in lr: +    x, y = bisect_left(numbers, l), bisect_right(numbers, r) +    if x == y: +        print((0)) +    elif numbers[y - 1] + 1 <= r: +        print((y - x)) -        ans[i + 1] = ans[i] -for _ in range(Q): -    l, r = list(map(int, input().split())) -    print((ans[r - 1] - ans[l - 1])) +        print((y - x - 1))