import sys

def main():

    n, q = list(map(int, sys.stdin.readline().split()))

    s = sys.stdin.readline().rstrip()

    lr = list(map(int, sys.stdin.read().split()))

    lr = list(zip(lr, lr))



    cumsum = [None] * (n + 1)

    cumsum[0] = 0



    flag = False

    for i in range(n):

        t = s[i]

        if t == 'A':

            flag = True

            cumsum[i+1] = cumsum[i]

        else:

            if t == 'C' and flag:

                cumsum[i+1] = cumsum[i] + 1

            else:

                cumsum[i+1] = cumsum[i]

            flag = False



    for l, r in lr:

        res = cumsum[r] - cumsum[l]

        print(res)



if __name__ == "__main__":

    main()
import sys



n, q = map(int, sys.stdin.readline().split())

s = '$' + sys.stdin.readline().rstrip()

lr = zip(*[map(int, sys.stdin.read().split())] * 2)



def main():

    res = [None] * (n + 1); res[0] = 0

    prev = '$'

    for i in range(1, n+1):

        res[i] = res[i-1]

        res[i] += (prev == 'A' and s[i] == 'C') & 1

        prev = s[i]

    

    for l, r in lr:

        yield res[r] - res[l]



if __name__ == '__main__':

    ans = main()

    print(*ans, sep='\n')

import sys


def main():
    n, q = list(map(int, sys.stdin.readline().split()))
    s = sys.stdin.readline().rstrip()
    lr = list(map(int, sys.stdin.read().split()))
    lr = list(zip(lr, lr))
    cumsum = [None] * (n + 1)
    cumsum[0] = 0
    flag = False
    for i in range(n):
        t = s[i]
        if t == "A":
            flag = True
            cumsum[i + 1] = cumsum[i]
        else:
            if t == "C" and flag:
                cumsum[i + 1] = cumsum[i] + 1
            else:
                cumsum[i + 1] = cumsum[i]
            flag = False
    for l, r in lr:
        res = cumsum[r] - cumsum[l]
        print(res)


if __name__ == "__main__":
    main()

import sys

n, q = map(int, sys.stdin.readline().split())
s = "$" + sys.stdin.readline().rstrip()
lr = zip(*[map(int, sys.stdin.read().split())] * 2)


def main():
    res = [None] * (n + 1)
    res[0] = 0
    prev = "$"
    for i in range(1, n + 1):
        res[i] = res[i - 1]
        res[i] += (prev == "A" and s[i] == "C") & 1
        prev = s[i]
    for l, r in lr:
        yield res[r] - res[l]


if __name__ == "__main__":
    ans = main()
    print(*ans, sep="\n")

+ +n, q = map(int, sys.stdin.readline().split()) +s = "$" + sys.stdin.readline().rstrip() +lr = zip(*[map(int, sys.stdin.read().split())] * 2) -    n, q = list(map(int, sys.stdin.readline().split())) -    s = sys.stdin.readline().rstrip() -    lr = list(map(int, sys.stdin.read().split())) -    lr = list(zip(lr, lr)) -    cumsum = [None] * (n + 1) -    cumsum[0] = 0 -    flag = False -    for i in range(n): -        t = s[i] -        if t == "A": -            flag = True -            cumsum[i + 1] = cumsum[i] -        else: -            if t == "C" and flag: -                cumsum[i + 1] = cumsum[i] + 1 -            else: -                cumsum[i + 1] = cumsum[i] -            flag = False +    res = [None] * (n + 1) +    res[0] = 0 +    prev = "$" +    for i in range(1, n + 1): +        res[i] = res[i - 1] +        res[i] += (prev == "A" and s[i] == "C") & 1 +        prev = s[i] -        res = cumsum[r] - cumsum[l] -        print(res) +        yield res[r] - res[l] -    main() +    ans = main() +    print(*ans, sep="\n")