Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
flag = [0, 0]
for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		flag.append(1)
	else:
		flag.append(0)
# print(flag)
ans = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
	for j in range(1,N+1):
		ans.append(0)
		
for i in range(N):
	for j in range(i,N):
		ans[i][j+1] = ans[i][j] + flag[j+1]
		ans[i+1][j] = ans[i][j] - flag[i+1]

for i in range(Q):
	print(ans[L[i]][R[i]])

# for i in range(Q):
# 	print(ans[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
sum = [0] * (N+1)
for i in range(1, N):
	if S[i-1] == 'A' and S[i] == 'C':
		sum[i+1] = sum[i] + 1
	else:
		sum[i+1] = sum[i]
# print(sum)


for i in range(Q):
	print(sum[R[i]] - sum[L[i]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
flag = [0, 0]
for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		flag.append(1)
	else:
		flag.append(0)
# print(flag)
ans = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
	for j in range(1,N+1):
		ans.append(0)
		
for i in range(N):
	for j in range(N):
		ans[i][j+1] = ans[i][j] + flag[j+1]
		ans[i+1][j] = ans[i][j] - flag[i+1]

for i in range(Q):
	print(ans[L[i]][R[i]])

# for i in range(Q):
# 	print(ans[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
sum = [0] * (N+1)
for i in range(1, N):
	if S[i-1] == 'A' and S[i] == 'C':
		sum[i+1] = sum[i] + 1
	else:
		sum[i+1] = sum[i]
# print(sum)


for i in range(Q):
	print(sum[R[i]] - sum[L[i]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
flag = []
for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		flag.append(1)
		i += 1
	else:
		flag.append(0)
# print(flag)


for i in range(Q):
	print(sum(flag[L[i]-1:R[i]-1]))

# for i in range(Q):
# 	print(ans[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
sum = [0] * (N+1)
for i in range(1, N):
	if S[i-1] == 'A' and S[i] == 'C':
		sum[i+1] = sum[i] + 1
	else:
		sum[i+1] = sum[i]
# print(sum)


for i in range(Q):
	print(sum[R[i]] - sum[L[i]])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
flag = []
for i in range(N):
	if S[i] == 'A' and S[i+1] == 'C':
		flag.append(1)
		i += 1
	else:
		flag.append(0)
# print(flag)

for i in range(Q):
	print(sum(flag[L[i]-1:R[i]-1]))

# for i in range(Q):
# 	print(ans[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
sum = [0] * (N+1)
for i in range(1, N):
	if S[i-1] == 'A' and S[i] == 'C':
		sum[i+1] = sum[i] + 1
	else:
		sum[i+1] = sum[i]
# print(sum)


for i in range(Q):
	print(sum[R[i]] - sum[L[i]])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
L = []
R = []
ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
flag = [0]*(N-1)

for i in range(N):
	if S[i] == 'A' and S[i+1] == 'C':
		flag[i] = 1
		i += 1
	else:
		pass
# print(flag)

for i in range(Q):
	print(sum(flag[L[i]-1:R[i]-1]))

# for i in range(Q):
# 	print(ans[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
sum = [0] * (N+1)
for i in range(1, N):
	if S[i-1] == 'A' and S[i] == 'C':
		sum[i+1] = sum[i] + 1
	else:
		sum[i+1] = sum[i]
# print(sum)


for i in range(Q):
	print(sum[R[i]] - sum[L[i]])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
L = []
R = []
ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)

for i in range(Q):
	cnt = 0
	for j in range(L[i]-1, R[i]-1):
		if S[j] == 'A' and S[j+1] == 'C':
			cnt += 1
		else:
			j += 1
	ans.append(cnt)

for i in range(Q):
	print(ans[i])

Fixed submission:
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
sum = [0] * (N+1)
for i in range(1, N):
	if S[i-1] == 'A' and S[i] == 'C':
		sum[i+1] = sum[i] + 1
	else:
		sum[i+1] = sum[i]
# print(sum)


for i in range(Q):
	print(sum[R[i]] - sum[L[i]])