Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(nq) for nq in input().split()]
S = input()
AC = []
for s in range(len(S)-2):
    if S[s:s+2] == "AC":
        AC.append(s+1)
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    ans = 0
    for ac in range(len(AC)):
        if l <= AC[ac] <= r-1:
            ans += 1
    print(ans)

Fixed submission:
N, Q = [int(nq) for nq in input().split()]
S = input()
AC = []
for s in range(len(S)-1):
    if S[s:s+2] == "AC":
        AC.append(1)
    else:
        AC.append(0)
CS = [0]*len(AC)
CS[0] = AC[0]
for i in range(len(AC)-1):
    CS[i+1] = CS[i] + AC[i+1]
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    if l == 1:
        print(CS[r-2])
    else:
        print(CS[r-2] - CS[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(nq) for nq in input().split()]
S = input()
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    ans = S[l-1:r].count("AC")
    print(ans)

Fixed submission:
N, Q = [int(nq) for nq in input().split()]
S = input()
AC = []
for s in range(len(S)-1):
    if S[s:s+2] == "AC":
        AC.append(1)
    else:
        AC.append(0)
CS = [0]*len(AC)
CS[0] = AC[0]
for i in range(len(AC)-1):
    CS[i+1] = CS[i] + AC[i+1]
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    if l == 1:
        print(CS[r-2])
    else:
        print(CS[r-2] - CS[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(nq) for nq in input().split()]
S = input()
ANS = []
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    ans = S[l-1:r].count("AC")
    print(ans)

Fixed submission:
N, Q = [int(nq) for nq in input().split()]
S = input()
AC = []
for s in range(len(S)-1):
    if S[s:s+2] == "AC":
        AC.append(1)
    else:
        AC.append(0)
CS = [0]*len(AC)
CS[0] = AC[0]
for i in range(len(AC)-1):
    CS[i+1] = CS[i] + AC[i+1]
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    if l == 1:
        print(CS[r-2])
    else:
        print(CS[r-2] - CS[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(nq) for nq in input().split()]
S = input()
ANS = []
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    ans = S[l-1:r].count("AC")
    ANS.append(ans)
    print(ANS[q])

Fixed submission:
N, Q = [int(nq) for nq in input().split()]
S = input()
AC = []
for s in range(len(S)-1):
    if S[s:s+2] == "AC":
        AC.append(1)
    else:
        AC.append(0)
CS = [0]*len(AC)
CS[0] = AC[0]
for i in range(len(AC)-1):
    CS[i+1] = CS[i] + AC[i+1]
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    if l == 1:
        print(CS[r-2])
    else:
        print(CS[r-2] - CS[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(nq) for nq in input().split()]
S = input()
ANS = []
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    ans = S[l-1:r].count("AC")
    ANS.append(ans)
for q in range(Q):
    print(ANS[q])

Fixed submission:
N, Q = [int(nq) for nq in input().split()]
S = input()
AC = []
for s in range(len(S)-1):
    if S[s:s+2] == "AC":
        AC.append(1)
    else:
        AC.append(0)
CS = [0]*len(AC)
CS[0] = AC[0]
for i in range(len(AC)-1):
    CS[i+1] = CS[i] + AC[i+1]
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    if l == 1:
        print(CS[r-2])
    else:
        print(CS[r-2] - CS[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(nq) for nq in input().split()]
S = input()
ANS = []
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    ans = 0
    for n in range(l-1, r-1):
        if S[n:n+2] == "AC":
            ans += 1
    ANS.append(ans)
for q in range(Q):
    print(ANS[q])

Fixed submission:
N, Q = [int(nq) for nq in input().split()]
S = input()
AC = []
for s in range(len(S)-1):
    if S[s:s+2] == "AC":
        AC.append(1)
    else:
        AC.append(0)
CS = [0]*len(AC)
CS[0] = AC[0]
for i in range(len(AC)-1):
    CS[i+1] = CS[i] + AC[i+1]
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    if l == 1:
        print(CS[r-2])
    else:
        print(CS[r-2] - CS[l-2])