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

s = eval(input())

c = [0]

flg = False

cnt = 0

for ss in s:

    if ss == 'C' and flg:

        cnt += 1

    flg = (ss == 'A')

    c.append(cnt)

# print(c)

for _ in range(q):

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

    # [l,r]



    res = c[r] - c[l - 1]

    if l >= 2 and s[l - 2:l] == 'AC':

        res -= 1

    print(res)

def main():

    import sys

    input = sys.stdin.readline



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

    s = input().rstrip()



    imos = [0] * (N + 1)

    for i in range(N - 1):

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

            imos[i + 2] += 1

    for i in range(N):

        imos[i + 1] += imos[i]



    ans = []

    for _ in range(Q):

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

        t = imos[r] - imos[l - 1] - (0 if imos[l] == imos[l - 1] else 1)

        ans.append(t)

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





if __name__ == '__main__':

    main()



# import sys

#

# sys.setrecursionlimit(10 ** 7)

#

# input = sys.stdin.readline

# rstrip()

# int(input())

# map(int, input().split())

n, q = list(map(int, input().split()))
s = eval(input())
c = [0]
flg = False
cnt = 0
for ss in s:
    if ss == "C" and flg:
        cnt += 1
    flg = ss == "A"
    c.append(cnt)
# print(c)
for _ in range(q):
    l, r = list(map(int, input().split()))
    # [l,r]
    res = c[r] - c[l - 1]
    if l >= 2 and s[l - 2 : l] == "AC":
        res -= 1
    print(res)

def main():
    import sys

    input = sys.stdin.readline
    N, Q = map(int, input().split())
    s = input().rstrip()
    imos = [0] * (N + 1)
    for i in range(N - 1):
        if s[i : i + 2] == "AC":
            imos[i + 2] += 1
    for i in range(N):
        imos[i + 1] += imos[i]
    ans = []
    for _ in range(Q):
        l, r = map(int, input().split())
        t = imos[r] - imos[l - 1] - (0 if imos[l] == imos[l - 1] else 1)
        ans.append(t)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

-n, q = list(map(int, input().split())) -s = eval(input()) -c = [0] -flg = False -cnt = 0 -for ss in s: -    if ss == "C" and flg: -        cnt += 1 -    flg = ss == "A" -    c.append(cnt) -# print(c) -for _ in range(q): -    l, r = list(map(int, input().split())) -    # [l,r] -    res = c[r] - c[l - 1] -    if l >= 2 and s[l - 2 : l] == "AC": -        res -= 1 -    print(res) +def main(): +    import sys + +    input = sys.stdin.readline +    N, Q = map(int, input().split()) +    s = input().rstrip() +    imos = [0] * (N + 1) +    for i in range(N - 1): +        if s[i : i + 2] == "AC": +            imos[i + 2] += 1 +    for i in range(N): +        imos[i + 1] += imos[i] +    ans = [] +    for _ in range(Q): +        l, r = map(int, input().split()) +        t = imos[r] - imos[l - 1] - (0 if imos[l] == imos[l - 1] else 1) +        ans.append(t) +    print(*ans, sep="\n") + + +if __name__ == "__main__": +    main() +# import sys +# +# sys.setrecursionlimit(10 ** 7) +# +# input = sys.stdin.readline +# rstrip() +# int(input()) +# map(int, input().split())