Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()

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

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = sum(C[l:r])
  print(ans)

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

C=[0]*(N)
c=0
for i in range(len(S)-1):
  if S[i:i+2]=="AC": c += 1
  C[i] = c

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = C[r-1] - C[l-1]
  print(ans)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())		# 5 7
S = "_" + input()

#print(N,Q,S)

a=[0]*N+1

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


for q in range(1,Q+1):
	l, r = map(int, input().split())		# 5 7
	print(a[r]-a[l])
	

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

C=[0]*(N)
c=0
for i in range(len(S)-1):
  if S[i:i+2]=="AC": c += 1
  C[i] = c

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = C[r-1] - C[l-1]
  print(ans)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())		# 5 7
S = "_" + input()

#print(N,Q,S)

a=[0]*N

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


for q in range(1,Q+1):
	l, r = map(int, input().split())		# 5 7
	print(a[r]-a[l])
	

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

C=[0]*(N)
c=0
for i in range(len(S)-1):
  if S[i:i+2]=="AC": c += 1
  C[i] = c

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = C[r-1] - C[l-1]
  print(ans)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())		# 5 7
S = input()

#print(N,Q,S)

L = "0 " + S.replace('AC', '1 0 ').replace('T', '0 ').replace('G', '0 ')
R = "0 " + S.replace('AC', '0 1 ').replace('T', '0 ').replace('G', '0 ')

L = list( map(int, L.split()) )	# 1 2 3 4 5 ...
R = list( map(int, R.split()) )	# 1 2 3 4 5 ...

#L = [0,1,2,3,4,5,6,7,8,9]
#R = [0,1,2,3,4,5,6,7,8,9]
#print(N,Q,S,L,R)
#print(N,Q,S)
#print("L", L)
#print("R", R)


from functools import reduce
#print( reduce(lambda x,y: x+y, L) )	#=> 10 (=sum(1,2,3,4))


for q in range(1,Q+1):
	ans=0
	l, r = map(int, input().split())		# 5 7
	
	if l!=r:
		X=L[l:l+1]
		Y=R[l+2:r+1]
		Z=X+Y+[0]
		
		ans = reduce(lambda x,y: x+y, Z)	#=> 10 (=sum(1,2,3,4))

		#print(l,r,"X=",X,"Y=",Y,"Z=",Z,ans)

	print(ans)
	

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

C=[0]*(N)
c=0
for i in range(len(S)-1):
  if S[i:i+2]=="AC": c += 1
  C[i] = c

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = C[r-1] - C[l-1]
  print(ans)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())		# 5 7
S = input()

#print(N,Q,S)

L = "0 " + S.replace('AC', '1 0 ').replace('T', '0 ').replace('G', '0 ')
R = "0 " + S.replace('AC', '0 1 ').replace('T', '0 ').replace('G', '0 ')

L = list( map(int, L.split()) )	# 1 2 3 4 5 ...
R = list( map(int, R.split()) )	# 1 2 3 4 5 ...

#L = [0,1,2,3,4,5,6,7,8,9]
#R = [0,1,2,3,4,5,6,7,8,9]
#print(N,Q,S,L,R)
#print(N,Q,S)
#print("L", L)
#print("R", R)


from functools import reduce
#print( reduce(lambda x,y: x+y, L) )	#=> 10 (=sum(1,2,3,4))


for q in range(1,Q+1):
	ans=0
	l, r = map(int, input().split())		# 5 7
	
	if l!=r:
		X=L[l:l+1]
		Y=R[l+2:r+1]
		Z=X+Y+[0]
		
		ans = reduce(lambda x,y: x+y, Z)	#=> 10 (=sum(1,2,3,4))

		#print(l,r,"X=",X,"Y=",Y,"Z=",Z,ans)

	print(ans)
	

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

C=[0]*(N)
c=0
for i in range(len(S)-1):
  if S[i:i+2]=="AC": c += 1
  C[i] = c

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = C[r-1] - C[l-1]
  print(ans)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())		# 5 7
S = input()

#print(N,Q,S)

L = "0 " + S.replace('AC', '1 0 ').replace('T', '0 ').replace('G', '0 ')
R = "0 " + S.replace('AC', '0 1 ').replace('T', '0 ').replace('G', '0 ')

L = list( map(int, L.split()) )	# 1 2 3 4 5 ...
R = list( map(int, R.split()) )	# 1 2 3 4 5 ...

#L = [0,1,2,3,4,5,6,7,8,9]
#R = [0,1,2,3,4,5,6,7,8,9]
#print(N,Q,S,L,R)
#print(N,Q,S)
#print("L", L)
#print("R", R)


from functools import reduce
#print( reduce(lambda x,y: x+y, L) )	#=> 10 (=sum(1,2,3,4))


for q in range(1,Q+1):
	ans=0
	l, r = map(int, input().split())		# 5 7
	
	if l!=r:
		X=L[l:l+1]
		Y=R[l+2:r+1]
		Z=X+Y+[0]
		
		ans = reduce(lambda x,y: x+y, Z)	#=> 10 (=sum(1,2,3,4))

		#print(l,r,"X=",X,"Y=",Y,"Z=",Z,ans)

	print(ans)
	

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

C=[0]*(N)
c=0
for i in range(len(S)-1):
  if S[i:i+2]=="AC": c += 1
  C[i] = c

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = C[r-1] - C[l-1]
  print(ans)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())		# 5 7
S = input()

#print(N,Q,S)

L = "0 " + S.replace('AC', '1 0 ').replace('T', '0 ').replace('G', '0 ')
R = "0 " + S.replace('AC', '0 1 ').replace('T', '0 ').replace('G', '0 ')

L = list( map(int, L.split()) )	# 1 2 3 4 5 ...
R = list( map(int, R.split()) )	# 1 2 3 4 5 ...

#L = [0,1,2,3,4,5,6,7,8,9]
#R = [0,1,2,3,4,5,6,7,8,9]
#print(N,Q,S,L,R)
#print(N,Q,S)
#print("L", L)
#print("R", R)


from functools import reduce
#print( reduce(lambda x,y: x+y, L) )	#=> 10 (=sum(1,2,3,4))


for q in range(1,Q+1):
	ans=0
	l, r = map(int, input().split())		# 5 7

	X=L[l:l+1]
	Y=R[l+2:r+1]
	Z=X+Y+[0]
	
	ans = reduce(lambda x,y: x+y, Z)	#=> 10 (=sum(1,2,3,4))

	#print(l,r,"X=",X,"Y=",Y,"Z=",Z,ans)

	print(ans)
	

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

C=[0]*(N)
c=0
for i in range(len(S)-1):
  if S[i:i+2]=="AC": c += 1
  C[i] = c

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = C[r-1] - C[l-1]
  print(ans)

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())		# 5 7
S = input()

#print(N,Q,S)

L = S.replace('AC', '1 0 ').replace('T', '0 ').replace('G', '0 ')
R = S.replace('AC', '0 1 ').replace('T', '0 ').replace('G', '0 ')

L = list( map(int, L.split()) )	# 1 2 3 4 5 ...
R = list( map(int, R.split()) )	# 1 2 3 4 5 ...

#L = [1,2,3,4,5,6,7,8,9]
#R = [1,2,3,4,5,6,7,8,9]
#print(N,Q,S,L,R)
#print(N,Q,S)
#print("L", L)
#print("R", R)


from functools import reduce
#print( reduce(lambda x,y: x+y, L) )	#=> 10 (=sum(1,2,3,4))


for q in range(1,Q+1):
	ans=0
	l, r = map(int, input().split())		# 5 7

	X=L[l-1:l]
	Y=R[l+1:r]
	Z=X+Y
	
	ans = reduce(lambda x,y: x+y, Z)	#=> 10 (=sum(1,2,3,4))

	#print(l,r,X,Y,Z,ans)

	print(ans)
	

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

C=[0]*(N)
c=0
for i in range(len(S)-1):
  if S[i:i+2]=="AC": c += 1
  C[i] = c

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = C[r-1] - C[l-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())		# 5 7
S = input()

#print(N,Q,S)

for q in range(1,Q+1):
	ans=0
	l, r = map(int, input().split())		# 5 7
	s = S[l-1:r]
	#print(l,r,s, len(s))
	
	x=-1
	for i in range(len(s)):
		if i<x: continue
		x = s.find("AC",i)
		if x>=0:
			ans += 1
			x+=2
		#print(s,i,x,ans)

	print(ans)
	

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

C=[0]*(N)
c=0
for i in range(len(S)-1):
  if S[i:i+2]=="AC": c += 1
  C[i] = c

#print(C)

for q in range(Q):
  l, r = map(int, input().split())
  l, r = l-1, r-1

  ans = C[r-1] - C[l-1]
  print(ans)