import bisect

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

s=eval(input())

ac=[]

for i in range(n-1):

  if s[i]=="A" and s[i+1]=="C":

    ac.append(i+1)

for i in range(q):

  a,b=list(map(int,input().split()))

  print((bisect.bisect_right(ac,b-1)-bisect.bisect_left(ac,a)))
import sys

import bisect

input=sys.stdin.readline

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

s=eval(input())

ac=[]

for i in range(n-1):

  if s[i]=="A" and s[i+1]=="C":

    ac.append(i+1)

for i in range(q):

  a,b=list(map(int,input().split()))

  print((bisect.bisect_right(ac,b-1)-bisect.bisect_left(ac,a)))
import bisect

n, q = list(map(int, input().split()))
s = eval(input())
ac = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ac.append(i + 1)
for i in range(q):
    a, b = list(map(int, input().split()))
    print((bisect.bisect_right(ac, b - 1) - bisect.bisect_left(ac, a)))

import sys
import bisect

input = sys.stdin.readline
n, q = list(map(int, input().split()))
s = eval(input())
ac = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        ac.append(i + 1)
for i in range(q):
    a, b = list(map(int, input().split()))
    print((bisect.bisect_right(ac, b - 1) - bisect.bisect_left(ac, a)))

+import sys +input = sys.stdin.readline