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



S = str(eval(input()))



ruisekiwa = [0]

for i in range(len(S)):

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

        ruisekiwa.append(ruisekiwa[-1]+1)

    else:

        ruisekiwa.append(ruisekiwa[-1])



# print(ruisekiwa)

for i in range(Q):

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

    print((ruisekiwa[r]-ruisekiwa[l]))

import sys



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



S = str(eval(input()))



ruisekiwa = [0]

for i in range(len(S)):

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

        ruisekiwa.append(ruisekiwa[-1]+1)

    else:

        ruisekiwa.append(ruisekiwa[-1])



# print(ruisekiwa)

for line in sys.stdin.readlines():

    l, r = list(map(int, line.strip().split()))

    print((ruisekiwa[r]-ruisekiwa[l]))

N, Q = list(map(int, input().split()))
S = str(eval(input()))
ruisekiwa = [0]
for i in range(len(S)):
    if S[i] == "C" and S[i - 1] == "A":
        ruisekiwa.append(ruisekiwa[-1] + 1)
    else:
        ruisekiwa.append(ruisekiwa[-1])
# print(ruisekiwa)
for i in range(Q):
    l, r = list(map(int, input().split()))
    print((ruisekiwa[r] - ruisekiwa[l]))

import sys

N, Q = list(map(int, input().split()))
S = str(eval(input()))
ruisekiwa = [0]
for i in range(len(S)):
    if S[i] == "C" and S[i - 1] == "A":
        ruisekiwa.append(ruisekiwa[-1] + 1)
    else:
        ruisekiwa.append(ruisekiwa[-1])
# print(ruisekiwa)
for line in sys.stdin.readlines():
    l, r = list(map(int, line.strip().split()))
    print((ruisekiwa[r] - ruisekiwa[l]))

+import sys + -for i in range(Q): -    l, r = list(map(int, input().split())) +for line in sys.stdin.readlines(): +    l, r = list(map(int, line.strip().split()))