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

S = eval(input())

len_S = len(S)



char = ""

ac = [0] * len_S

val = 0

for i in range(N):

    char += S[i]

    # print(char)

    # print(char[len(char)-2:len(char)+1])

    if char[len(char)-2:len(char)+1] == "AC":

        val += 1

    ac[i] = val

# print(ac)



for _ in range(Q):

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

    l -= 1

    r -= 1

    ans = ac[r] - ac[l]

    print(ans)
# 解答通り

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

S = eval(input())

t = [0] * (N+1)



for i in range(N):

    t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)



for i in range(Q):

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

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

    print(ans)

N, Q = list(map(int, input().split()))
S = eval(input())
len_S = len(S)
char = ""
ac = [0] * len_S
val = 0
for i in range(N):
    char += S[i]
    # print(char)
    # print(char[len(char)-2:len(char)+1])
    if char[len(char) - 2 : len(char) + 1] == "AC":
        val += 1
    ac[i] = val
# print(ac)
for _ in range(Q):
    l, r = list(map(int, input().split()))
    l -= 1
    r -= 1
    ans = ac[r] - ac[l]
    print(ans)

# 解答通り
N, Q = list(map(int, input().split()))
S = eval(input())
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == "AC" else 0)
for i in range(Q):
    l, r = list(map(int, input().split()))
    ans = t[r - 1] - t[l - 1]
    print(ans)

+# 解答通り -len_S = len(S) -char = "" -ac = [0] * len_S -val = 0 +t = [0] * (N + 1) -    char += S[i] -    # print(char) -    # print(char[len(char)-2:len(char)+1]) -    if char[len(char) - 2 : len(char) + 1] == "AC": -        val += 1 -    ac[i] = val -# print(ac) -for _ in range(Q): +    t[i + 1] = t[i] + (1 if S[i : i + 2] == "AC" else 0) +for i in range(Q): -    l -= 1 -    r -= 1 -    ans = ac[r] - ac[l] +    ans = t[r - 1] - t[l - 1]