import bisect

import re

import sys



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

S = sys.stdin.readline()

P = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]



r = re.compile('AC')

a = [x.start() for x in r.finditer(S)]



if a:

    for q in P:

        p1 = bisect.bisect_left(a, q[0] - 1)

        p2 = bisect.bisect_right(a, q[1] - 2)

        print((p2 - p1))

else:

    for q in P:

        print((0))
import sys



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

S = sys.stdin.readline()

P = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]



a = [0] * N

for i in range(N - 1):

    a[i + 1] = a[i] + int(S[i] == 'A' and S[i + 1] == 'C')



for q in P:

    print((a[q[1] - 1] - a[q[0] - 1]))
import bisect
import re
import sys

N, Q = list(map(int, input().split()))
S = sys.stdin.readline()
P = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]
r = re.compile("AC")
a = [x.start() for x in r.finditer(S)]
if a:
    for q in P:
        p1 = bisect.bisect_left(a, q[0] - 1)
        p2 = bisect.bisect_right(a, q[1] - 2)
        print((p2 - p1))
else:
    for q in P:
        print((0))

import sys

N, Q = list(map(int, input().split()))
S = sys.stdin.readline()
P = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]
a = [0] * N
for i in range(N - 1):
    a[i + 1] = a[i] + int(S[i] == "A" and S[i + 1] == "C")
for q in P:
    print((a[q[1] - 1] - a[q[0] - 1]))

-import bisect -import re -r = re.compile("AC") -a = [x.start() for x in r.finditer(S)] -if a: -    for q in P: -        p1 = bisect.bisect_left(a, q[0] - 1) -        p2 = bisect.bisect_right(a, q[1] - 2) -        print((p2 - p1)) -else: -    for q in P: -        print((0)) +a = [0] * N +for i in range(N - 1): +    a[i + 1] = a[i] + int(S[i] == "A" and S[i + 1] == "C") +for q in P: +    print((a[q[1] - 1] - a[q[0] - 1]))