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

l=[0 for i in range(n)]

for i,v in enumerate(list(input().replace("AC","X!"))):

    l[i]=l[i-1]+(v=="!")

for c in range(q):

    h,m=list(map(int,input().split()))

    print((l[m-1]-l[h-1]))
n,q=list(map(int,input().split()))

t=eval(input())



a=[0]*n

from collections import defaultdict

tail=defaultdict(int)

for i in range(n-1):

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

        a[i+1]+=1

        tail[i]+=1

from itertools import accumulate

a=list(accumulate(a))

for _ in range(q):

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

    l,r=l-1,r-1

    if l==0:print((a[r]))

    else:

        print((a[r]-a[l-1]-tail[l-1]))
n, q = list(map(int, input().split()))
l = [0 for i in range(n)]
for i, v in enumerate(list(input().replace("AC", "X!"))):
    l[i] = l[i - 1] + (v == "!")
for c in range(q):
    h, m = list(map(int, input().split()))
    print((l[m - 1] - l[h - 1]))

n, q = list(map(int, input().split()))
t = eval(input())
a = [0] * n
from collections import defaultdict

tail = defaultdict(int)
for i in range(n - 1):
    if t[i] == "A" and t[i + 1] == "C":
        a[i + 1] += 1
        tail[i] += 1
from itertools import accumulate

a = list(accumulate(a))
for _ in range(q):
    l, r = list(map(int, input().split()))
    l, r = l - 1, r - 1
    if l == 0:
        print((a[r]))
    else:
        print((a[r] - a[l - 1] - tail[l - 1]))

-l = [0 for i in range(n)] -for i, v in enumerate(list(input().replace("AC", "X!"))): -    l[i] = l[i - 1] + (v == "!") -for c in range(q): -    h, m = list(map(int, input().split())) -    print((l[m - 1] - l[h - 1])) +t = eval(input()) +a = [0] * n +from collections import defaultdict + +tail = defaultdict(int) +for i in range(n - 1): +    if t[i] == "A" and t[i + 1] == "C": +        a[i + 1] += 1 +        tail[i] += 1 +from itertools import accumulate + +a = list(accumulate(a)) +for _ in range(q): +    l, r = list(map(int, input().split())) +    l, r = l - 1, r - 1 +    if l == 0: +        print((a[r])) +    else: +        print((a[r] - a[l - 1] - tail[l - 1]))