# C

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

s = str(eval(input()))

s_flag = [0] * n

v = 0

for i in range(n-1):

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

        v += 1

    s_flag[i+1] = v



for i in range(q):

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

    l -= 1

    r -= 1

    ans = s_flag[r] - s_flag[l]

    print(ans)
import sys

input = sys.stdin.readline



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

s = str(eval(input()))

ac = [0] * n

for i in range(1, n):

    ac[i] = ac[i-1]

    if(s[i-1] == "A" and s[i] == "C"):

        ac[i] += 1

for i in range(q):

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

    print((ac[r-1] - ac[l-1]))
# C
n, q = list(map(int, input().split()))
s = str(eval(input()))
s_flag = [0] * n
v = 0
for i in range(n - 1):
    if s[i : i + 2] == "AC":
        v += 1
    s_flag[i + 1] = v
for i in range(q):
    l, r = list(map(int, input().split()))
    l -= 1
    r -= 1
    ans = s_flag[r] - s_flag[l]
    print(ans)

import sys

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

-# C +import sys + +input = sys.stdin.readline -s_flag = [0] * n -v = 0 -for i in range(n - 1): -    if s[i : i + 2] == "AC": -        v += 1 -    s_flag[i + 1] = v +ac = [0] * n +for i in range(1, n): +    ac[i] = ac[i - 1] +    if s[i - 1] == "A" and s[i] == "C": +        ac[i] += 1 -    l -= 1 -    r -= 1 -    ans = s_flag[r] - s_flag[l] -    print(ans) +    print((ac[r - 1] - ac[l - 1]))