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

S = eval(input())

memo = [0 for _ in [0]*(N+1)]

for i in range(2,N+1):

    memo[i] = memo[i-1] + int(S[i-2:i]=="AC")

for _ in range(Q):

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

    print((memo[r]-memo[l]))
import sys

input = sys.stdin.readline

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

S = input()

dp = [0]*(N+1)

cnt = 0

for i in range(2,N+1):

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

        cnt += 1

    dp[i] = cnt

ans = []

for _ in [0]*Q:

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

    ans.append(dp[r] - dp[l])

print(*ans, sep="\n")

N, Q = list(map(int, input().split()))
S = eval(input())
memo = [0 for _ in [0] * (N + 1)]
for i in range(2, N + 1):
    memo[i] = memo[i - 1] + int(S[i - 2 : i] == "AC")
for _ in range(Q):
    l, r = list(map(int, input().split()))
    print((memo[r] - memo[l]))

import sys

input = sys.stdin.readline
N, Q = map(int, input().split())
S = input()
dp = [0] * (N + 1)
cnt = 0
for i in range(2, N + 1):
    if S[i - 1] == "C" and S[i - 2] == "A":
        cnt += 1
    dp[i] = cnt
ans = []
for _ in [0] * Q:
    l, r = map(int, input().split())
    ans.append(dp[r] - dp[l])
print(*ans, sep="\n")

-N, Q = list(map(int, input().split())) -S = eval(input()) -memo = [0 for _ in [0] * (N + 1)] +import sys + +input = sys.stdin.readline +N, Q = map(int, input().split()) +S = input() +dp = [0] * (N + 1) +cnt = 0 -    memo[i] = memo[i - 1] + int(S[i - 2 : i] == "AC") -for _ in range(Q): -    l, r = list(map(int, input().split())) -    print((memo[r] - memo[l])) +    if S[i - 1] == "C" and S[i - 2] == "A": +        cnt += 1 +    dp[i] = cnt +ans = [] +for _ in [0] * Q: +    l, r = map(int, input().split()) +    ans.append(dp[r] - dp[l]) +print(*ans, sep="\n")