import bisect



n, q = list(map(int, input().split()))

s = input().strip()

lrs = [list(map(int, input().split())) for _ in range(q)]



indices = []

for i, (c0, c1) in enumerate(zip(s, s[1:])):

    if c0 == 'A' and c1 == 'C':

        indices.append(i)



indices_c = [i + 1 for i in indices]

for (l, r) in lrs:

    li = bisect.bisect_left(indices, l - 1)

    ri = bisect.bisect_left(indices_c, r)

    print((ri - li))
import sys



input = sys.stdin.readline



ri = lambda: int(eval(input()))

rs = lambda: input().rstrip()

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

rsl = lambda: input().rstrip().split()

ris = lambda n: [ri() for _ in range(n)]

rss = lambda n: [rs() for _ in range(n)]

rils = lambda n: [ril() for _ in range(n)]

rsls = lambda n: [rsl() for _ in range(n)]



n, q = ril()

s = rs()

acc = [0] * n

for i in range(1, n):

    if s[i - 1:i + 1] == 'AC':

        acc[i] = acc[i - 1] + 1

    else:

        acc[i] = acc[i - 1]

for _ in range(q):

    l, r = ril()

    print((acc[r - 1] - acc[l - 1]))
import bisect

n, q = list(map(int, input().split()))
s = input().strip()
lrs = [list(map(int, input().split())) for _ in range(q)]
indices = []
for i, (c0, c1) in enumerate(zip(s, s[1:])):
    if c0 == "A" and c1 == "C":
        indices.append(i)
indices_c = [i + 1 for i in indices]
for (l, r) in lrs:
    li = bisect.bisect_left(indices, l - 1)
    ri = bisect.bisect_left(indices_c, r)
    print((ri - li))

import sys

input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
n, q = ril()
s = rs()
acc = [0] * n
for i in range(1, n):
    if s[i - 1 : i + 1] == "AC":
        acc[i] = acc[i - 1] + 1
    else:
        acc[i] = acc[i - 1]
for _ in range(q):
    l, r = ril()
    print((acc[r - 1] - acc[l - 1]))

-import bisect +import sys -n, q = list(map(int, input().split())) -s = input().strip() -lrs = [list(map(int, input().split())) for _ in range(q)] -indices = [] -for i, (c0, c1) in enumerate(zip(s, s[1:])): -    if c0 == "A" and c1 == "C": -        indices.append(i) -indices_c = [i + 1 for i in indices] -for (l, r) in lrs: -    li = bisect.bisect_left(indices, l - 1) -    ri = bisect.bisect_left(indices_c, r) -    print((ri - li)) +input = sys.stdin.readline +ri = lambda: int(eval(input())) +rs = lambda: input().rstrip() +ril = lambda: list(map(int, input().split())) +rsl = lambda: input().rstrip().split() +ris = lambda n: [ri() for _ in range(n)] +rss = lambda n: [rs() for _ in range(n)] +rils = lambda n: [ril() for _ in range(n)] +rsls = lambda n: [rsl() for _ in range(n)] +n, q = ril() +s = rs() +acc = [0] * n +for i in range(1, n): +    if s[i - 1 : i + 1] == "AC": +        acc[i] = acc[i - 1] + 1 +    else: +        acc[i] = acc[i - 1] +for _ in range(q): +    l, r = ril() +    print((acc[r - 1] - acc[l - 1]))