n, q = list(map(int, input().split()))

s = eval(input())

a = [0] * n

t = 0

for i in range(1, n):

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

        t += 1

    a[i] += t

for i in range(q):

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

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

def main():

    import sys

    input = sys.stdin.readline

    n, q = list(map(int, input().rstrip('\n').split()))

    s = str(input().rstrip('\n'))

    ss = [0] * n

    t = 0

    for i in range(n):

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

            t += 1

        ss[i] = t

    for l, r in [list(map(int, input().split())) for _ in range(q)]:

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





if __name__ == '__main__':

    main()

n, q = list(map(int, input().split()))
s = eval(input())
a = [0] * n
t = 0
for i in range(1, n):
    if s[i - 1] == "A" and s[i] == "C":
        t += 1
    a[i] += t
for i in range(q):
    l, r = list(map(int, input().split()))
    print((a[r - 1] - a[l - 1]))

def main():
    import sys

    input = sys.stdin.readline
    n, q = list(map(int, input().rstrip("\n").split()))
    s = str(input().rstrip("\n"))
    ss = [0] * n
    t = 0
    for i in range(n):
        if s[i] == "C" and s[i - 1] == "A":
            t += 1
        ss[i] = t
    for l, r in [list(map(int, input().split())) for _ in range(q)]:
        print((ss[r - 1] - ss[l - 1]))


if __name__ == "__main__":
    main()

-n, q = list(map(int, input().split())) -s = eval(input()) -a = [0] * n -t = 0 -for i in range(1, n): -    if s[i - 1] == "A" and s[i] == "C": -        t += 1 -    a[i] += t -for i in range(q): -    l, r = list(map(int, input().split())) -    print((a[r - 1] - a[l - 1])) +def main(): +    import sys + +    input = sys.stdin.readline +    n, q = list(map(int, input().rstrip("\n").split())) +    s = str(input().rstrip("\n")) +    ss = [0] * n +    t = 0 +    for i in range(n): +        if s[i] == "C" and s[i - 1] == "A": +            t += 1 +        ss[i] = t +    for l, r in [list(map(int, input().split())) for _ in range(q)]: +        print((ss[r - 1] - ss[l - 1])) + + +if __name__ == "__main__": +    main()