def main():

    N, Q = (int(i) for i in input().split())

    S = eval(input())

    C = [0] * (len(S) + 1)

    for i in range(1, len(S)):

        C[i+1] = C[i] + (1 if S[i] == "C" and S[i-1] == "A" else 0)



    for q in range(Q):

        le, ri = (int(i) for i in input().split())

        print((C[ri] - C[le]))





if __name__ == '__main__':

    main()

def main():

    N, Q = (int(i) for i in input().split())

    S = eval(input())

    LR = [[int(i) for i in input().split()] for j in range(Q)]

    AC = [0]*N

    for i, s in enumerate(S):

        AC[i] = AC[i-1]

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

            AC[i] += 1

    S = list([0] + AC)

    for le, ri in LR:

        print((S[ri] - S[le]))





if __name__ == '__main__':

    main()

def main():
    N, Q = (int(i) for i in input().split())
    S = eval(input())
    C = [0] * (len(S) + 1)
    for i in range(1, len(S)):
        C[i + 1] = C[i] + (1 if S[i] == "C" and S[i - 1] == "A" else 0)
    for q in range(Q):
        le, ri = (int(i) for i in input().split())
        print((C[ri] - C[le]))


if __name__ == "__main__":
    main()

def main():
    N, Q = (int(i) for i in input().split())
    S = eval(input())
    LR = [[int(i) for i in input().split()] for j in range(Q)]
    AC = [0] * N
    for i, s in enumerate(S):
        AC[i] = AC[i - 1]
        if i > 0 and S[i - 1] == "A" and s == "C":
            AC[i] += 1
    S = list([0] + AC)
    for le, ri in LR:
        print((S[ri] - S[le]))


if __name__ == "__main__":
    main()

-    C = [0] * (len(S) + 1) -    for i in range(1, len(S)): -        C[i + 1] = C[i] + (1 if S[i] == "C" and S[i - 1] == "A" else 0) -    for q in range(Q): -        le, ri = (int(i) for i in input().split()) -        print((C[ri] - C[le])) +    LR = [[int(i) for i in input().split()] for j in range(Q)] +    AC = [0] * N +    for i, s in enumerate(S): +        AC[i] = AC[i - 1] +        if i > 0 and S[i - 1] == "A" and s == "C": +            AC[i] += 1 +    S = list([0] + AC) +    for le, ri in LR: +        print((S[ri] - S[le]))