import bisect



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

S = eval(input()) + ' '

x, y = [], []



for i in range(N):

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

        x.append(i+1)

        y.append(i+2)



for i in range(Q):

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



    idx = [-1, -1]



    idx[0] = bisect.bisect_left(x, l)

    idx[1] = bisect.bisect_right(y, r)



    print((idx[1] - idx[0]))
import sys



input = sys.stdin.readline



def main():

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

    S = eval(input())

    

    count = [0] * N

    

    for i in range(1, N):

        if S[i-1:i+1] == 'AC': count[i] = count[i-1] + 1

        else: count[i] = count[i-1]

    

    for i in range(Q):

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

        

        print((count[r-1] - count[l-1]))



if __name__ == '__main__':

    main()
import bisect

N, Q = list(map(int, input().split()))
S = eval(input()) + " "
x, y = [], []
for i in range(N):
    if S[i : i + 2] == "AC":
        x.append(i + 1)
        y.append(i + 2)
for i in range(Q):
    l, r = list(map(int, input().split()))
    idx = [-1, -1]
    idx[0] = bisect.bisect_left(x, l)
    idx[1] = bisect.bisect_right(y, r)
    print((idx[1] - idx[0]))

import sys

input = sys.stdin.readline


def main():
    N, Q = list(map(int, input().split()))
    S = eval(input())
    count = [0] * N
    for i in range(1, N):
        if S[i - 1 : i + 1] == "AC":
            count[i] = count[i - 1] + 1
        else:
            count[i] = count[i - 1]
    for i in range(Q):
        l, r = list(map(int, input().split()))
        print((count[r - 1] - count[l - 1]))


if __name__ == "__main__":
    main()

-import bisect +import sys -N, Q = list(map(int, input().split())) -S = eval(input()) + " " -x, y = [], [] -for i in range(N): -    if S[i : i + 2] == "AC": -        x.append(i + 1) -        y.append(i + 2) -for i in range(Q): -    l, r = list(map(int, input().split())) -    idx = [-1, -1] -    idx[0] = bisect.bisect_left(x, l) -    idx[1] = bisect.bisect_right(y, r) -    print((idx[1] - idx[0])) +input = sys.stdin.readline + + +def main(): +    N, Q = list(map(int, input().split())) +    S = eval(input()) +    count = [0] * N +    for i in range(1, N): +        if S[i - 1 : i + 1] == "AC": +            count[i] = count[i - 1] + 1 +        else: +            count[i] = count[i - 1] +    for i in range(Q): +        l, r = list(map(int, input().split())) +        print((count[r - 1] - count[l - 1])) + + +if __name__ == "__main__": +    main()