# -*- coding: utf-8 -*-



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

S = eval(input())

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



lst = [0] * N

count = 0

for i in range(N - 1):

    if S[i] == 'A' and S[i + 1] == 'C':

        count += 1

    lst[i + 1] = count



for l, r in LR:

    ans = lst[r-1] - lst[l-1]

    print(ans)

# -*- coding: utf-8 -*-



import sys

input = sys.stdin.readline



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

S = eval(input())

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



lst = [0] * N

count = 0

for i in range(N - 1):

    if S[i] == 'A' and S[i + 1] == 'C':

        count += 1

    lst[i + 1] = count



for l, r in LR:

    ans = lst[r-1] - lst[l-1]

    print(ans)

# -*- coding: utf-8 -*-
N, Q = list(map(int, input().split()))
S = eval(input())
LR = [list(map(int, input().split())) for i in range(Q)]
lst = [0] * N
count = 0
for i in range(N - 1):
    if S[i] == "A" and S[i + 1] == "C":
        count += 1
    lst[i + 1] = count
for l, r in LR:
    ans = lst[r - 1] - lst[l - 1]
    print(ans)

# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
N, Q = list(map(int, input().split()))
S = eval(input())
LR = [list(map(int, input().split())) for i in range(Q)]
lst = [0] * N
count = 0
for i in range(N - 1):
    if S[i] == "A" and S[i + 1] == "C":
        count += 1
    lst[i + 1] = count
for l, r in LR:
    ans = lst[r - 1] - lst[l - 1]
    print(ans)

+import sys + +input = sys.stdin.readline