def ss():

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

    s = eval(input())

    lis=[0]*N

     

    count = 0

    for i in range(1,len(s)):

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

            count +=1

        lis[i]+=count

    for i in range(Q):

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

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



ss()
import sys

input = sys.stdin.readline

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

s = input().rstrip()

lis=[0]*N

 

count = 0

for i in range(1,len(s)):

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

        count +=1

    lis[i]+=count

for i in range(Q):

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

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

def ss():
    N, Q = list(map(int, input().split()))
    s = eval(input())
    lis = [0] * N
    count = 0
    for i in range(1, len(s)):
        if s[i - 1] == "A" and s[i] == "C":
            count += 1
        lis[i] += count
    for i in range(Q):
        l, r = list(map(int, input().split()))
        print((lis[r - 1] - lis[l - 1]))


ss()

import sys

input = sys.stdin.readline
N, Q = list(map(int, input().split()))
s = input().rstrip()
lis = [0] * N
count = 0
for i in range(1, len(s)):
    if s[i - 1] == "A" and s[i] == "C":
        count += 1
    lis[i] += count
for i in range(Q):
    l, r = list(map(int, input().split()))
    print((lis[r - 1] - lis[l - 1]))

-def ss(): -    N, Q = list(map(int, input().split())) -    s = eval(input()) -    lis = [0] * N -    count = 0 -    for i in range(1, len(s)): -        if s[i - 1] == "A" and s[i] == "C": -            count += 1 -        lis[i] += count -    for i in range(Q): -        l, r = list(map(int, input().split())) -        print((lis[r - 1] - lis[l - 1])) +import sys - -ss() +input = sys.stdin.readline +N, Q = list(map(int, input().split())) +s = input().rstrip() +lis = [0] * N +count = 0 +for i in range(1, len(s)): +    if s[i - 1] == "A" and s[i] == "C": +        count += 1 +    lis[i] += count +for i in range(Q): +    l, r = list(map(int, input().split())) +    print((lis[r - 1] - lis[l - 1]))