N, Q = list(map(int, input().split()))

S = eval(input())

c = [0]*N

for i in range(1, N):

    c[i] = c[i-1]

    if S[i-1]=="A" and S[i]=="C":

        c[i] = c[i-1] + 1

for _ in range(Q):

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

    print((c[r-1]-c[l-1]))
import re

N, Q = list(map(int, input().split()))

S = eval(input())

query = [list(map(int, input().split())) for _ in range(Q)]

s = re.sub(r"AC", "0", S)

accum = [0 for _ in range(N)]

for i in range(1, N):

    accum[i] = accum[i-1]

    if S[i-1]=="A" and S[i]=="C":

        accum[i] += + 1



for l,r in query:

    print((accum[r-1]-accum[l-1]))
N, Q = list(map(int, input().split()))
S = eval(input())
c = [0] * N
for i in range(1, N):
    c[i] = c[i - 1]
    if S[i - 1] == "A" and S[i] == "C":
        c[i] = c[i - 1] + 1
for _ in range(Q):
    l, r = list(map(int, input().split()))
    print((c[r - 1] - c[l - 1]))

import re

N, Q = list(map(int, input().split()))
S = eval(input())
query = [list(map(int, input().split())) for _ in range(Q)]
s = re.sub(r"AC", "0", S)
accum = [0 for _ in range(N)]
for i in range(1, N):
    accum[i] = accum[i - 1]
    if S[i - 1] == "A" and S[i] == "C":
        accum[i] += +1
for l, r in query:
    print((accum[r - 1] - accum[l - 1]))

+import re + -c = [0] * N +query = [list(map(int, input().split())) for _ in range(Q)] +s = re.sub(r"AC", "0", S) +accum = [0 for _ in range(N)] -    c[i] = c[i - 1] +    accum[i] = accum[i - 1] -        c[i] = c[i - 1] + 1 -for _ in range(Q): -    l, r = list(map(int, input().split())) -    print((c[r - 1] - c[l - 1])) +        accum[i] += +1 +for l, r in query: +    print((accum[r - 1] - accum[l - 1]))