Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input() 
data = [ tuple(map(int, input().split())) for _ in range(Q) ] 

counter = [0 for _ in range(Q)]
index = -1
while True:
	index = S.find("AC", index+1)

	if index == -1:
		break
	
	for i, (l, r ) in enumerate(data):
		if l-1 <= index < r-1:
			counter[i] += 1


for res in counter:
	print(res)


Fixed submission:
N, Q = map(int, input().split())
S = input() 

t = [0] * (N + 1) 

for i in range(N):
	t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input() 
data = [ tuple(map(int, input().split())) for _ in range(Q) ] 

counter = [0 for _ in range(Q)]
index = -1
while True:
	index = S.find("AC", index+1)

	if index == -1:
		break
	
	for i, (l, r ) in enumerate(data):
		if l-1 <= index < r-1:
			counter[i] += 1


for res in counter:
	print(res)



# print(indexList)

# for (l, r) in data:
	# print(indexList[l-1: r-1])
	# print(sum(indexList[l-1: r-1]))

Fixed submission:
N, Q = map(int, input().split())
S = input() 

t = [0] * (N + 1) 

for i in range(N):
	t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)

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

Buggy python submission (verdict: Runtime Error):
S = input() 
data = [ tuple(map(int, input().split())) for _ in range(Q) ] 

counter = [0 for _ in range(Q)]
index = -1
while True:
	index = S.find("AC", index+1)

	if index == -1:
		break
	
	for i, (l, r ) in enumerate(data):
		if l-1 <= index < r-1:
			counter[i] += 1

for res in counter:
	print(res)


Fixed submission:
N, Q = map(int, input().split())
S = input() 

t = [0] * (N + 1) 

for i in range(N):
	t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input() 
data = [ tuple(map(int, input().split())) for _ in range(Q) ] 

indexList = [0 for _ in range(N)]
index = -1
while True:
	index = S.find("AC", index+1)

	if index == -1:
		break
	
	indexList[index] = 1

# print(indexList)

for (l, r) in data:
	# print(indexList[l-1: r-1])
	print(sum(indexList[l-1: r-1]))

Fixed submission:
N, Q = map(int, input().split())
S = input() 

t = [0] * (N + 1) 

for i in range(N):
	t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input() 
data = [ tuple(map(int, input().split())) for _ in range(Q) ] 

indexList = []
index = -1
while True:
	index = S.find("AC", index+1)

	if index == -1:
		break
	
	indexList.append(index)

# print(indexList)

for (l, r) in data:
	ls = filter(lambda i: i >= l-1, indexList)
	rs = filter(lambda i: i+1 < r, ls)
	# print(list(rs))
	print(len(list(rs)))


Fixed submission:
N, Q = map(int, input().split())
S = input() 

t = [0] * (N + 1) 

for i in range(N):
	t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)

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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input() 
data = [ tuple(map(int, input().split())) for _ in range(Q) ] 

for (l, r) in data:
	print(S[l-1:r].count("AC"))



Fixed submission:
N, Q = map(int, input().split())
S = input() 

t = [0] * (N + 1) 

for i in range(N):
	t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)

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