Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N-2):
  if S[i:i+2] == 'AC':
    index[i] = 1
for _ in range(Q):
  l, r = map(int,input().split())
  print(index[l-1:r-1].count(1))

Fixed submission:
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N-2):
  if S[i:i+2] == 'AC':
    index[i] = 1
for _ in range(Q):
  l, r = map(int,input().split())
  print(sum(index[l-1:r-1]))

Fixed submission:
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])

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

index = [0] *(N+1)

for i in range(N-2):
  if S[i:i+2] == 'AC':
    index[i] = 1

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

Fixed submission:
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])

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

Fixed submission:
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])

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

Fixed submission:
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])

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

Fixed submission:
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S = input()
"""
points = []
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    points.append(i)
for _ in range(Q):
  r, l = map(int,input().split())
  List = [n for n in points if n >= r -1 and n+1 <= l-1]
  print(len(List))
"""
for i in range(Q):
  r, l = map(int,input().split())
  S_short = S[r-1:l]
  counter = 0
  for j in range(len(S_short)-1):
    if S_short[j]=='A' and S_short[j+1] == 'C':
      counter +=1
  print(counter)


Fixed submission:
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S = input()
points = []
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    points.append(i)
for _ in range(Q):
  r, l = map(int,input().split())
  List = [n for n in points if n >= r -1 and n+1 <= l-1]
  print(len(List))

Fixed submission:
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int,input().split())
S = input()
points = []
for i in range(N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    points.append(i)
for _ in range(Q):
  r, l = map(int,input().split())
  List = [n for n in points if n >= r -1 and n+1 <= l-1]
  print(len(List))

Fixed submission:
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])