import bisect



def solve():

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

    S = eval(input())

    

    index = []

    for i in range(N-1):

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

            index.append(i+1)

    for _ in range(Q):

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

        print((bisect.bisect_left(index, r) - bisect.bisect_left(index, l)))

        

solve()
def solve():

    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 _ in range(Q):

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

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

        

solve()
import bisect


def solve():
    N, Q = list(map(int, input().split()))
    S = eval(input())
    index = []
    for i in range(N - 1):
        if S[i : i + 2] == "AC":
            index.append(i + 1)
    for _ in range(Q):
        l, r = list(map(int, input().split()))
        print((bisect.bisect_left(index, r) - bisect.bisect_left(index, l)))


solve()

def solve():
    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 _ in range(Q):
        l, r = list(map(int, input().split()))
        print((t[r - 1] - t[l - 1]))


solve()

-import bisect - - -    index = [] -    for i in range(N - 1): -        if S[i : i + 2] == "AC": -            index.append(i + 1) +    t = [0] * (N + 1) +    for i in range(N): +        t[i + 1] = t[i] + (1 if S[i : i + 2] == "AC" else 0) -        print((bisect.bisect_left(index, r) - bisect.bisect_left(index, l))) +        print((t[r - 1] - t[l - 1]))