#coding: utf-8

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

S = eval(input())

T = [0]

for i in range(N-1):

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

        T.append(T[i] + 1)

    else:

        T.append(T[i])

for j in range(Q):

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

    print((T[r-1] - T[l-1]))
# coding: utf-8

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

s = eval(input())

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

T = [0]

cnt = 0

for i in range(n-1):

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

        cnt += 1

    T.append(cnt)

for l, r in lr:

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

# coding: utf-8
n, q = list(map(int, input().split()))
s = eval(input())
lr = [list(map(int, input().split())) for _ in range(q)]
T = [0]
cnt = 0
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        cnt += 1
    T.append(cnt)
for l, r in lr:
    print((T[r - 1] - T[l - 1]))

-N, Q = list(map(int, input().split())) -S = eval(input()) +n, q = list(map(int, input().split())) +s = eval(input()) +lr = [list(map(int, input().split())) for _ in range(q)] -for i in range(N - 1): -    if S[i] == "A" and S[i + 1] == "C": -        T.append(T[i] + 1) -    else: -        T.append(T[i]) -for j in range(Q): -    l, r = list(map(int, input().split())) +cnt = 0 +for i in range(n - 1): +    if s[i] == "A" and s[i + 1] == "C": +        cnt += 1 +    T.append(cnt) +for l, r in lr: