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

S = eval(input())



AC = [0] * N



flag = 0

for i, s in enumerate(S):

    if s == 'C':

        if flag == 1:

            AC[i] = AC[i - 1] + 1

            flag = 0

        else:

            AC[i] = AC[i - 1]

            flag = 0

    elif s == 'A':

        AC[i] = AC[i - 1]

        flag = 1

    else:

        AC[i] = AC[i - 1]

        flag = 0





ans = [0] * Q

for q in range(Q):

    l, r = [int(x) - 1 for x in input().split()]

    ans[q] = AC[r] - AC[l]



for q in range(Q):

    print((ans[q]))

import sys





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

S = eval(input())



AC = [0] * N



for i in range(1, N):

    a = 0

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

        a = 1

    AC[i] = AC[i - 1] + a



LR = [list(map(int, x.split())) for x in sys.stdin.readlines()]



for l, r in LR:

    print((AC[r - 1] - AC[l - 1]))

N, Q = list(map(int, input().split()))
S = eval(input())
AC = [0] * N
flag = 0
for i, s in enumerate(S):
    if s == "C":
        if flag == 1:
            AC[i] = AC[i - 1] + 1
            flag = 0
        else:
            AC[i] = AC[i - 1]
            flag = 0
    elif s == "A":
        AC[i] = AC[i - 1]
        flag = 1
    else:
        AC[i] = AC[i - 1]
        flag = 0
ans = [0] * Q
for q in range(Q):
    l, r = [int(x) - 1 for x in input().split()]
    ans[q] = AC[r] - AC[l]
for q in range(Q):
    print((ans[q]))

import sys

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

+import sys + -flag = 0 -for i, s in enumerate(S): -    if s == "C": -        if flag == 1: -            AC[i] = AC[i - 1] + 1 -            flag = 0 -        else: -            AC[i] = AC[i - 1] -            flag = 0 -    elif s == "A": -        AC[i] = AC[i - 1] -        flag = 1 -    else: -        AC[i] = AC[i - 1] -        flag = 0 -ans = [0] * Q -for q in range(Q): -    l, r = [int(x) - 1 for x in input().split()] -    ans[q] = AC[r] - AC[l] -for q in range(Q): -    print((ans[q])) +for i in range(1, N): +    a = 0 +    if S[i - 1] == "A" and S[i] == "C": +        a = 1 +    AC[i] = AC[i - 1] + a +LR = [list(map(int, x.split())) for x in sys.stdin.readlines()] +for l, r in LR: +    print((AC[r - 1] - AC[l - 1]))