Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = []

for i in range(n + 1):
    a.append(s[:i].count('AC'))

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

Fixed submission:
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

for i in range(q):
    print(s[a[i]-1:b[i]].count('AC'))


Fixed submission:
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())

    c = s[x-1:y]
    d = c.count('AC')
    print(d)

Fixed submission:
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

    c = s[a[i]-1:b[i]]
    d = c.count('AC')
    print(d)

Fixed submission:
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

ss = []
ll = []
for i in range(q):
    c = s[a[i]-1:b[i]]
    d = c.count('AC')
    print(d)

Fixed submission:
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

ss = []
ll = []
for i in range(n):
    c = s[a[i]:b[i]]
    d = c.count('AC')
    print(d)

Fixed submission:
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

ss = []
ll = []
for i in range(n):
    c = s[a[i]:b[i]]
    d = c.count('AC')
    print(len(c)-len(d))

Fixed submission:
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

for i in range(q):
    c = s[a[i]-1:b[i]]
    d = c.replace('AC','A')
    print(len(c)-len(d))

Fixed submission:
n, q = map(int, input().split())
s = str(input())
d = [list(map(int, input().split())) for i in range(q)]
a = [0,0]
cnt = 0
for i in range(1, n):
    if s[i-1]+s[i] == 'AC':
        cnt += 1
    a.append(cnt)

for i in range(q):
    print(a[d[i][1]]-a[d[i][0]])