from itertools import accumulate

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

s = eval(input())

L = [0]*n



for i in range(n-1):

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

        L[i] = 0

        L[i+1] = 1



LL = list(accumulate(L))

for i in range(q):

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

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

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

a = eval(input())

L = [0]*n



for i in range(n-1):

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

        L[i] = 1



L = [0]+L

for i in range(n):

    L[i+1] += L[i]

#print(L)

for i in range(k):

    c,d = list(map(int,input().split()))

    print((L[d-1]-L[c-1]))
from itertools import accumulate

n, q = list(map(int, input().split()))
s = eval(input())
L = [0] * n
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        L[i] = 0
        L[i + 1] = 1
LL = list(accumulate(L))
for i in range(q):
    l, r = list(map(int, input().split()))
    print((LL[r - 1] - LL[l - 1]))

n, k = list(map(int, input().split()))
a = eval(input())
L = [0] * n
for i in range(n - 1):
    if a[i] == "A" and a[i + 1] == "C":
        L[i] = 1
L = [0] + L
for i in range(n):
    L[i + 1] += L[i]
# print(L)
for i in range(k):
    c, d = list(map(int, input().split()))
    print((L[d - 1] - L[c - 1]))

-from itertools import accumulate - -n, q = list(map(int, input().split())) -s = eval(input()) +n, k = list(map(int, input().split())) +a = eval(input()) -    if s[i] == "A" and s[i + 1] == "C": -        L[i] = 0 -        L[i + 1] = 1 -LL = list(accumulate(L)) -for i in range(q): -    l, r = list(map(int, input().split())) -    print((LL[r - 1] - LL[l - 1])) +    if a[i] == "A" and a[i + 1] == "C": +        L[i] = 1 +L = [0] + L +for i in range(n): +    L[i + 1] += L[i] +# print(L) +for i in range(k): +    c, d = list(map(int, input().split())) +    print((L[d - 1] - L[c - 1]))