import sys

input = sys.stdin.readline

import numpy as np

import bisect

left = bisect.bisect_left

right = bisect.bisect_right



def question():

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

    s = eval(input())

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

    a = [i for i in range(n-1) if s[i:i+2]=="AC"]



    for i in range(q):

        left_index = left(a, lr[i][0]-1)

        right_index = right(a, lr[i][1]-2)

        print((right_index - left_index))



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

arr = input()



ac_count = [0]

ac = 0

for i in range(1, n):

    if arr[i-1:i+1] == "AC":

        ac += 1

    ac_count.append(ac)



ans = []



for _ in range(q):

    left, right = map(int, input().split())

    ans.append(ac_count[right-1] - ac_count[left-1])



print(*ans, sep="\n")

import sys

input = sys.stdin.readline
import numpy as np
import bisect

left = bisect.bisect_left
right = bisect.bisect_right


def question():
    n, q = list(map(int, input().split()))
    s = eval(input())
    lr = [list(map(int, input().split())) for i in range(q)]
    a = [i for i in range(n - 1) if s[i : i + 2] == "AC"]
    for i in range(q):
        left_index = left(a, lr[i][0] - 1)
        right_index = right(a, lr[i][1] - 2)
        print((right_index - left_index))


question()

n, q = map(int, input().split())
arr = input()
ac_count = [0]
ac = 0
for i in range(1, n):
    if arr[i - 1 : i + 1] == "AC":
        ac += 1
    ac_count.append(ac)
ans = []
for _ in range(q):
    left, right = map(int, input().split())
    ans.append(ac_count[right - 1] - ac_count[left - 1])
print(*ans, sep="\n")

-import sys - -input = sys.stdin.readline -import numpy as np -import bisect - -left = bisect.bisect_left -right = bisect.bisect_right - - -def question(): -    n, q = list(map(int, input().split())) -    s = eval(input()) -    lr = [list(map(int, input().split())) for i in range(q)] -    a = [i for i in range(n - 1) if s[i : i + 2] == "AC"] -    for i in range(q): -        left_index = left(a, lr[i][0] - 1) -        right_index = right(a, lr[i][1] - 2) -        print((right_index - left_index)) - - -question() +n, q = map(int, input().split()) +arr = input() +ac_count = [0] +ac = 0 +for i in range(1, n): +    if arr[i - 1 : i + 1] == "AC": +        ac += 1 +    ac_count.append(ac) +ans = [] +for _ in range(q): +    left, right = map(int, input().split()) +    ans.append(ac_count[right - 1] - ac_count[left - 1]) +print(*ans, sep="\n")