from sys import stdin





def main():

    readline = stdin.readline

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

    S = readline().strip()

    L = []

    R = []

    for i in range(Q):

        *LR, = list(map(int, readline().split()))

        L.append(LR[0] - 1)

        R.append(LR[1] - 1)

    AC = []

    pre = None

    cnt = 0

    for c in S:

        if c == "A":

            pre = "A"

        elif pre == "A" and c == "C":

            cnt += 1

            pre = None

        elif pre == "A":

            pre = None

        AC.append(cnt)

    for l, r in zip(L, R):

        print((AC[r] - AC[l]))

    return





main()

from sys import stdin





def main():

    readline = stdin.readline

    read = stdin.read

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

    S = readline().strip()

    * LR, = [int(x) - 1 for x in read().split()]

    AC = []

    pre = None

    cnt = 0

    for c in S:

        if c == "A":

            pre = "A"

        elif pre == "A" and c == "C":

            cnt += 1

            pre = None

        elif pre == "A":

            pre = None

        AC.append(cnt)

    for l, r in zip(*[iter(LR)] * 2):

        print((AC[r] - AC[l]))

    return





main()

from sys import stdin


def main():
    readline = stdin.readline
    N, Q = list(map(int, readline().split()))
    S = readline().strip()
    L = []
    R = []
    for i in range(Q):
        (*LR,) = list(map(int, readline().split()))
        L.append(LR[0] - 1)
        R.append(LR[1] - 1)
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(L, R):
        print((AC[r] - AC[l]))
    return


main()

from sys import stdin


def main():
    readline = stdin.readline
    read = stdin.read
    N, Q = list(map(int, readline().split()))
    S = readline().strip()
    (*LR,) = [int(x) - 1 for x in read().split()]
    AC = []
    pre = None
    cnt = 0
    for c in S:
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC.append(cnt)
    for l, r in zip(*[iter(LR)] * 2):
        print((AC[r] - AC[l]))
    return


main()

+    read = stdin.read -    L = [] -    R = [] -    for i in range(Q): -        (*LR,) = list(map(int, readline().split())) -        L.append(LR[0] - 1) -        R.append(LR[1] - 1) +    (*LR,) = [int(x) - 1 for x in read().split()] -    for l, r in zip(L, R): +    for l, r in zip(*[iter(LR)] * 2):