Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit

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

S = input()

AC = []
for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        AC.append(i)

ans = []

for i in range(Q):
    li, ri = map(int, input().split())

    count = 0
    for ac in AC:
        if ac < li - 1:
            count += 1
        else:
            break
    for ac in reversed(AC):
        if ri - 1 < ac + 1:
            count += 1
        else:
            break
    print(len(AC) - count)


Fixed submission:
from sys import exit

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

S = input()

AC = [0] * N

c = 0

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    AC[i + 1] = c

for _ in range(Q):
    li, ri = map(int, input().split())
    print(AC[ri - 1] - AC[li - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit

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

S = input()

AC = {}
for i in range(len(S) - 1):
    if S[i] == 'A':
        if S[i + 1] == 'C':
            AC[i] = True
            continue
    AC[i] = False

ans = []

for i in range(Q):
    li, ri = map(int, input().split())
    count = 0
    for i in range(li - 1, ri - 1):
        if AC[i]:
            count += 1
    ans.append(count)

for a in ans:
    print(a)


Fixed submission:
from sys import exit

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

S = input()

AC = [0] * N

c = 0

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    AC[i + 1] = c

for _ in range(Q):
    li, ri = map(int, input().split())
    print(AC[ri - 1] - AC[li - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit

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

S = input()

AC = []
for i in range(len(S) - 1):
    if S[i] == 'A':
        if S[i + 1] == 'C':
            AC.append(i)

ans = []

for i in range(Q):
    li, ri = map(int, input().split())
    count = 0
    if li - ri > len(S) / 2:
        for ac in AC:
            if ac < li - 1:
                count += 1
            else:
                break
        for ac in reversed(AC):
            if ri - 1 < ac + 1:
                count += 1
            else:
                break
        ans.append(len(AC) - count)
    else:
        for i in range(li - 1, ri - 1):
            if i in AC:
                count += 1
        ans.append(count)

for a in ans:
    print(a)


Fixed submission:
from sys import exit

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

S = input()

AC = [0] * N

c = 0

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    AC[i + 1] = c

for _ in range(Q):
    li, ri = map(int, input().split())
    print(AC[ri - 1] - AC[li - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit

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

S = input()

AC = []
for i in range(len(S) - 1):
    if S[i] == 'A':
        if S[i + 1] == 'C':
            AC.append(i)

ans = []

for i in range(Q):
    li, ri = map(int, input().split())
    count = 0
    for i in range(li - 1, ri - 1):
        if i in AC:
            count += 1
    ans.append(count)

for a in ans:
    print(a)


Fixed submission:
from sys import exit

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

S = input()

AC = [0] * N

c = 0

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    AC[i + 1] = c

for _ in range(Q):
    li, ri = map(int, input().split())
    print(AC[ri - 1] - AC[li - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit

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

S = input()

AC = []
for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        AC.append(i)

ans = []

for i in range(Q):
    li, ri = map(int, input().split())

    count = 0
    for ac in AC:
        if ac < li - 1:
            count += 1
        else:
            break
    for ac in reversed(AC):
        if ri - 1 < ac + 1:
            count += 1
        else:
            break
    ans.append(len(AC) - count)

for a in ans:
    print(a)


Fixed submission:
from sys import exit

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

S = input()

AC = [0] * N

c = 0

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    AC[i + 1] = c

for _ in range(Q):
    li, ri = map(int, input().split())
    print(AC[ri - 1] - AC[li - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit

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

S = input()

AC = []
for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        AC.append(i)

ans = []

for i in range(Q):
    li, ri = map(int, input().split())

    count = 0
    for ac in AC:
        if ac < li - 1 or ri - 1 < ac + 1:
            count += 1
    ans.append(len(AC) - count)

for a in ans:
    print(a)


Fixed submission:
from sys import exit

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

S = input()

AC = [0] * N

c = 0

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    AC[i + 1] = c

for _ in range(Q):
    li, ri = map(int, input().split())
    print(AC[ri - 1] - AC[li - 1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import exit

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

S = input()

AC = []
for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        AC.append(i)

l = []
r = []

for i in range(Q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

for i in range(Q):
    count = 0
    for ac in AC:
        if ac < l[i] - 1 or r[i] - 1 < ac + 1:
            count += 1
    print(len(AC) - count)


Fixed submission:
from sys import exit

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

S = input()

AC = [0] * N

c = 0

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    AC[i + 1] = c

for _ in range(Q):
    li, ri = map(int, input().split())
    print(AC[ri - 1] - AC[li - 1])