Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
idx = [i for i in range(N - 1) if S[i:i+2] == 'AC']

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(sum([i >= l - 1 and i <= r - 2 for i in idx]))


Fixed submission:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
m = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        m[i] = m[i-1] + 1
    else:
        m[i] = m[i-1]

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(m[r - 1] - m[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
idx = [S[i:i+2] == 'AC' for i in range(N - 1)]

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(sum(idx[l - 1:r - 1]))


Fixed submission:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
m = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        m[i] = m[i-1] + 1
    else:
        m[i] = m[i-1]

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(m[r - 1] - m[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(sum([S[i:i+2] == 'AC' for i in range(l - 1, r - 1)]))


Fixed submission:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
m = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        m[i] = m[i-1] + 1
    else:
        m[i] = m[i-1]

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(m[r - 1] - m[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    res = 0
    for j in range(l - 1, r - 1):
        if S[j:j+2] == 'AC':
            res += 1
    print(res)


Fixed submission:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
m = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        m[i] = m[i-1] + 1
    else:
        m[i] = m[i-1]

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(m[r - 1] - m[l - 1])

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
l, r = [0] * Q, [0] * Q

for i in range(Q):
    l[i], r[i] = [int(x) for x in input().split()]

for i in range(Q):
    res = 0
    for j in range(l[i] - 1, r[i] - 1):
        if S[j:j+2] == 'AC':
            res += 1
    print(res)


Fixed submission:
# https://atcoder.jp/contests/abc122/tasks/abc122_c

N, Q = [int(x) for x in input().split()]
S = input().strip()
m = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        m[i] = m[i-1] + 1
    else:
        m[i] = m[i-1]

for i in range(Q):
    l, r = [int(x) for x in input().split()]
    print(m[r - 1] - m[l - 1])