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

S = eval(input())

B = [0] * N

for i in range(N-1):

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

        B[i] = 1

for i in range(1, N-1):

    B[i] += B[i-1]

for i in range(Q):

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

    print((B[r-2] - B[l-2]))
# coding: utf-8

import sys

import itertools



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

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, Q = lr()

S = sr()

ac = [0] * (N-1)

for i, x in enumerate(zip(S[:], S[1:])):

    if x[0] == 'A' and x[1] == 'C':

        ac[i] = 1



cum = list(itertools.accumulate(ac))

for _ in range(Q):

    l, r = lr()

    result = cum[r-2]

    if l > 1:

        result -= cum[l-2]

    print(result)

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

# coding: utf-8
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, Q = lr()
S = sr()
ac = [0] * (N - 1)
for i, x in enumerate(zip(S[:], S[1:])):
    if x[0] == "A" and x[1] == "C":
        ac[i] = 1
cum = list(itertools.accumulate(ac))
for _ in range(Q):
    l, r = lr()
    result = cum[r - 2]
    if l > 1:
        result -= cum[l - 2]
    print(result)

-N, Q = list(map(int, input().split())) -S = eval(input()) -B = [0] * N -for i in range(N - 1): -    if S[i] == "A" and S[i + 1] == "C": -        B[i] = 1 -for i in range(1, N - 1): -    B[i] += B[i - 1] -for i in range(Q): -    l, r = list(map(int, input().split())) -    print((B[r - 2] - B[l - 2])) +# coding: utf-8 +import sys +import itertools + +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N, Q = lr() +S = sr() +ac = [0] * (N - 1) +for i, x in enumerate(zip(S[:], S[1:])): +    if x[0] == "A" and x[1] == "C": +        ac[i] = 1 +cum = list(itertools.accumulate(ac)) +for _ in range(Q): +    l, r = lr() +    result = cum[r - 2] +    if l > 1: +        result -= cum[l - 2] +    print(result)