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

S = eval(input())

cnt_array = [0] * (N+1)

ans = [0] * Q

for i in range(N):

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

        cnt_array[i+1] = 1 + cnt_array[i]

    else:

        cnt_array[i+1] = cnt_array[i]

for i in range(Q):

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

    ans[i] = cnt_array[r-1] - cnt_array[l-1]

for i in ans:

    print(i)
import sys

input = sys.stdin.readline

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

S = eval(input())

S_array = [0] * N

for i in range(N):

    S_array[i] = S_array[i-1]

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

        S_array[i] += 1

for _ in range(Q):

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

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

import sys

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

+import sys + +input = sys.stdin.readline -cnt_array = [0] * (N + 1) -ans = [0] * Q +S_array = [0] * N -    if i != N - 1 and S[i] == "A" and S[i + 1] == "C": -        cnt_array[i + 1] = 1 + cnt_array[i] -    else: -        cnt_array[i + 1] = cnt_array[i] -for i in range(Q): +    S_array[i] = S_array[i - 1] +    if S[i - 1] == "A" and S[i] == "C": +        S_array[i] += 1 +for _ in range(Q): -    ans[i] = cnt_array[r - 1] - cnt_array[l - 1] -for i in ans: -    print(i) +    print((S_array[r - 1] - S_array[l - 1]))