Buggy python submission (verdict: Time Limit Exceeded):
# TLE(lr&ACsが重そう)
'''
ACが出現する場所を抑えておいて、
range内に何回出てくるか探索
'''
N, Q = list(map(int, input().split()))
S = list(str(input()))
questions = [tuple(map(int, input().split())) for _ in range(Q)]
ACs = [0] * N
for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        ACs[i] = 1

for q in questions:
    print(sum(ACs[q[0]-1:q[1]-1]))


Fixed submission:
N, Q = list(map(int, input().split()))
S = list(str(input()))
questions = [tuple(map(int, input().split())) for _ in range(Q)]
ACs = [0] * N

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

for q in questions:
    print(ACs[q[1]-1] - ACs[q[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = list(map(int, input().split()))
S = list(str(input()))
ACs = [0] * N
for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        ACs[i] = 1

for q in range(Q):
    l, r = list(map(int, input().split()))
    print(sum(ACs[l-1:r-1]))


Fixed submission:
N, Q = list(map(int, input().split()))
S = list(str(input()))
questions = [tuple(map(int, input().split())) for _ in range(Q)]
ACs = [0] * N

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

for q in questions:
    print(ACs[q[1]-1] - ACs[q[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int, input().split()))
S=list(str(input()))
ACs=[]
for i in range(len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        ACs.append(i)
ACs=set(ACs)
for q in range(Q):
    l,r = list(map(int, input().split()))
    lr=set(range(l-1,r-1))
    print(len(lr&ACs))

Fixed submission:
N, Q = list(map(int, input().split()))
S = list(str(input()))
questions = [tuple(map(int, input().split())) for _ in range(Q)]
ACs = [0] * N

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

for q in questions:
    print(ACs[q[1]-1] - ACs[q[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int, input().split()))
S=list(str(input()))
ACs=[]
for i in range(len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        ACs.append(i)
ACs=set(ACs)
for q in range(Q):
    l,r = list(map(lambda x:int(x)-1, input().split()))
    lr=set(range(l,r))
    print(len(lr&ACs))

Fixed submission:
N, Q = list(map(int, input().split()))
S = list(str(input()))
questions = [tuple(map(int, input().split())) for _ in range(Q)]
ACs = [0] * N

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

for q in questions:
    print(ACs[q[1]-1] - ACs[q[0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int, input().split()))
S=list(str(input()))
ACs=[]
for i in range(len(S)-1):
    if S[i]=='A' and S[i+1]=='C':
        ACs.append(i)

for q in range(Q):
    l,r = list(map(lambda x:int(x)-1, input().split()))
    lr=list(range(l,r))
    print(len(set(lr)&set(ACs)))



Fixed submission:
N, Q = list(map(int, input().split()))
S = list(str(input()))
questions = [tuple(map(int, input().split())) for _ in range(Q)]
ACs = [0] * N

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

for q in questions:
    print(ACs[q[1]-1] - ACs[q[0]-1])