from numpy import cumsum

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

*s,=eval(input())

l=[0]*q

r=[0]*q

for i in range(q):

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

a=[0]*n

for i in range(n-1):

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

        a[i]=1

b=[0]+list(cumsum(a))

for i in range(q):

    print((b[r[i]-1]-b[l[i]-1]))
from itertools import accumulate

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

*s,=eval(input())

l=[0]*q

r=[0]*q

for i in range(q):

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

a=[0]*n

for i in range(n-1):

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

        a[i]=1

b=[0]+list(accumulate(a))

for i in range(q):

    print((b[r[i]-1]-b[l[i]-1]))
from numpy import cumsum

n, q = list(map(int, input().split()))
(*s,) = eval(input())
l = [0] * q
r = [0] * q
for i in range(q):
    l[i], r[i] = list(map(int, input().split()))
a = [0] * n
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        a[i] = 1
b = [0] + list(cumsum(a))
for i in range(q):
    print((b[r[i] - 1] - b[l[i] - 1]))

from itertools import accumulate

n, q = list(map(int, input().split()))
(*s,) = eval(input())
l = [0] * q
r = [0] * q
for i in range(q):
    l[i], r[i] = list(map(int, input().split()))
a = [0] * n
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        a[i] = 1
b = [0] + list(accumulate(a))
for i in range(q):
    print((b[r[i] - 1] - b[l[i] - 1]))

-from numpy import cumsum +from itertools import accumulate -b = [0] + list(cumsum(a)) +b = [0] + list(accumulate(a))