inpl = lambda: list(map(int,input().split()))

N, Q = inpl()

S = eval(input())



T = [0]*N

a_flag = False

ac_num = 0

for i in range(N):

    if S[i] == 'A':

        a_flag = True

    elif a_flag and S[i] == 'C':

        ac_num += 1

        a_flag = False

    else:

        a_flag = False

    T[i] = ac_num



for _ in range(Q):

    l, r = inpl()

    print((T[r-1]-T[l-1]))
from bisect import bisect_left

import sys

sys.setrecursionlimit(10**9)

input = lambda: sys.stdin.readline().rstrip()

inpl = lambda: list(map(int,input().split()))



N, Q = inpl()

S = eval(input())



ACs = []

for i in range(N-1):

    if S[i:i+2] == 'AC':

        ACs.append(i)



for i in range(Q):

    l, r = inpl()

    Nl = bisect_left(ACs,l-1)

    Nr = bisect_left(ACs,r-1)

    print((Nr-Nl))
inpl = lambda: list(map(int, input().split()))
N, Q = inpl()
S = eval(input())
T = [0] * N
a_flag = False
ac_num = 0
for i in range(N):
    if S[i] == "A":
        a_flag = True
    elif a_flag and S[i] == "C":
        ac_num += 1
        a_flag = False
    else:
        a_flag = False
    T[i] = ac_num
for _ in range(Q):
    l, r = inpl()
    print((T[r - 1] - T[l - 1]))

from bisect import bisect_left
import sys

sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int, input().split()))
N, Q = inpl()
S = eval(input())
ACs = []
for i in range(N - 1):
    if S[i : i + 2] == "AC":
        ACs.append(i)
for i in range(Q):
    l, r = inpl()
    Nl = bisect_left(ACs, l - 1)
    Nr = bisect_left(ACs, r - 1)
    print((Nr - Nl))

+from bisect import bisect_left +import sys + +sys.setrecursionlimit(10**9) +input = lambda: sys.stdin.readline().rstrip() -T = [0] * N -a_flag = False -ac_num = 0 -for i in range(N): -    if S[i] == "A": -        a_flag = True -    elif a_flag and S[i] == "C": -        ac_num += 1 -        a_flag = False -    else: -        a_flag = False -    T[i] = ac_num -for _ in range(Q): +ACs = [] +for i in range(N - 1): +    if S[i : i + 2] == "AC": +        ACs.append(i) +for i in range(Q): -    print((T[r - 1] - T[l - 1])) +    Nl = bisect_left(ACs, l - 1) +    Nr = bisect_left(ACs, r - 1) +    print((Nr - Nl))