#n=int(input())

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



s=list(eval(input()))

#bl=list(map(int,input().split()))

#l=[list(map(int,input().split())) for i in range(n)]



count=[0]*n



for i in range(1,n):

    st=s[i-1:i+1]

    if st==["A","C"]:

        count[i]=count[i-1]+1

    else:

        count[i]=count[i-1]



for i in range(q):

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

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

#n = int(input())

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

#bl = list(map(int, input().split()))

#al=[list(input()) for i in range(n)]

s = eval(input())

acnum = [0]*(n+1)

for i in range(2, n+1):

    if s[i-2:i] == 'AC':

        acnum[i] += acnum[i-1]+1

    else:

        acnum[i] += acnum[i-1]



for i in range(q):

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

    print((acnum[r]-acnum[l]))

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

# n = int(input())
n, q = list(map(int, input().split()))
# bl = list(map(int, input().split()))
# al=[list(input()) for i in range(n)]
s = eval(input())
acnum = [0] * (n + 1)
for i in range(2, n + 1):
    if s[i - 2 : i] == "AC":
        acnum[i] += acnum[i - 1] + 1
    else:
        acnum[i] += acnum[i - 1]
for i in range(q):
    l, r = list(map(int, input().split()))
    print((acnum[r] - acnum[l]))

-# n=int(input()) +# n = int(input()) -s = list(eval(input())) -# bl=list(map(int,input().split())) -# l=[list(map(int,input().split())) for i in range(n)] -count = [0] * n -for i in range(1, n): -    st = s[i - 1 : i + 1] -    if st == ["A", "C"]: -        count[i] = count[i - 1] + 1 +# bl = list(map(int, input().split())) +# al=[list(input()) for i in range(n)] +s = eval(input()) +acnum = [0] * (n + 1) +for i in range(2, n + 1): +    if s[i - 2 : i] == "AC": +        acnum[i] += acnum[i - 1] + 1 -        count[i] = count[i - 1] +        acnum[i] += acnum[i - 1] -    print((count[r - 1] - count[l - 1])) +    print((acnum[r] - acnum[l]))