import sys

input=sys.stdin.readline

sys.setrecursionlimit(10**9)

from bisect import bisect_left

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

S=eval(input())

A=[]

for i in range(len(S)-1):

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

        A.append(i)

for _ in range(q):

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

    left=bisect_left(A,l-1)

    right=bisect_left(A,r-1)

    print((right-left))
import sys

input=sys.stdin.readline

sys.setrecursionlimit(10**9)

from itertools import accumulate

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

S=eval(input())

A=[0]*(n-1)

for i in range(len(S)-1):

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

        A[i]=1

B=[0]+list(accumulate(A))

for _ in range(q):

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

    print((B[r-1]-B[l-1]))
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**9)
from bisect import bisect_left

n, q = list(map(int, input().split()))
S = eval(input())
A = []
for i in range(len(S) - 1):
    if S[i] == "A" and S[i + 1] == "C":
        A.append(i)
for _ in range(q):
    l, r = list(map(int, input().split()))
    left = bisect_left(A, l - 1)
    right = bisect_left(A, r - 1)
    print((right - left))

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**9)
from itertools import accumulate

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

-from bisect import bisect_left +from itertools import accumulate -A = [] +A = [0] * (n - 1) -        A.append(i) +        A[i] = 1 +B = [0] + list(accumulate(A)) -    left = bisect_left(A, l - 1) -    right = bisect_left(A, r - 1) -    print((right - left)) +    print((B[r - 1] - B[l - 1]))