import bisect

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

s=list(eval(input()))

former_list=[]

latter_list=[]



for i in range(n-1):

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

        former_list.append(i+1)

        latter_list.append(i+2)

for j in range(q):

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

    start=bisect.bisect_left(former_list,l)

    end=bisect.bisect_right(latter_list,r)

    print((end-start))


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

s=list(eval(input()))

sum=[0]*n



for i in range(n-1):

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

        sum[i+1]=sum[i]+1

    else:

        sum[i+1]=sum[i]

for j in range(q):

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

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

n, q = list(map(int, input().split()))
s = list(eval(input()))
former_list = []
latter_list = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        former_list.append(i + 1)
        latter_list.append(i + 2)
for j in range(q):
    l, r = list(map(int, input().split()))
    start = bisect.bisect_left(former_list, l)
    end = bisect.bisect_right(latter_list, r)
    print((end - start))

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

-import bisect - -former_list = [] -latter_list = [] +sum = [0] * n -        former_list.append(i + 1) -        latter_list.append(i + 2) +        sum[i + 1] = sum[i] + 1 +    else: +        sum[i + 1] = sum[i] -    start = bisect.bisect_left(former_list, l) -    end = bisect.bisect_right(latter_list, r) -    print((end - start)) +    print((sum[r - 1] - sum[l - 1]))