from itertools import accumulate

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

S = eval(input())

rs = [0] * N



for i in range(N - 1):

    if S[i] + S[i + 1] == "AC":

        rs[i + 1] = 1



rm = [0] + list(accumulate(rs))



for i in range(Q):

    ans = 0

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

    if S[l] == "C":

        ans -= 1

    ans = rm[r] - rm[l]

    print(ans)
from itertools import accumulate

import sys

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

S = eval(input())

rs = [0] * N



for i in range(N - 1):

    if S[i] + S[i + 1] == "AC":

        rs[i + 1] = 1



rm = [0] + list(accumulate(rs))



for i in range(Q):

    ans = 0

    l, r = list(map(int, sys.stdin.readline().split()))

    if S[l] == "C":

        ans -= 1

    ans = rm[r] - rm[l]

    print(ans)
from itertools import accumulate

N, Q = list(map(int, input().split()))
S = eval(input())
rs = [0] * N
for i in range(N - 1):
    if S[i] + S[i + 1] == "AC":
        rs[i + 1] = 1
rm = [0] + list(accumulate(rs))
for i in range(Q):
    ans = 0
    l, r = list(map(int, input().split()))
    if S[l] == "C":
        ans -= 1
    ans = rm[r] - rm[l]
    print(ans)

from itertools import accumulate
import sys

N, Q = list(map(int, input().split()))
S = eval(input())
rs = [0] * N
for i in range(N - 1):
    if S[i] + S[i + 1] == "AC":
        rs[i + 1] = 1
rm = [0] + list(accumulate(rs))
for i in range(Q):
    ans = 0
    l, r = list(map(int, sys.stdin.readline().split()))
    if S[l] == "C":
        ans -= 1
    ans = rm[r] - rm[l]
    print(ans)

+import sys -    l, r = list(map(int, input().split())) +    l, r = list(map(int, sys.stdin.readline().split()))