Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])
      
      
      
  
  
  
  


Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n-1):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)
x.append(x[-1])  

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])
      
      
      
  
  
  
  


Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n-1):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  
for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])
      
      
      
  
  
  
  


Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n-1):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n):
  if s[j]=="A" and s[j+1]=="C":
      ans+=1
      x.append(ans)
  
for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])
      
      
      
  
  
  
  


Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n-1):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,q):
  for k in range(l[j],r[j]):
    if s[k]=="A" and s[k+1]=="C":
      ans+=1
    else:
      ans+=0
  x.append(ans)
  ans=0
  
for m in range(0,q):
  print(x[m])
      
      
      
  
  
  
  


Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n-1):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  x1,y1=[int(i) for i in input().split()]
  x.append(x1)
  y.append(y1)
  
for j in range(0,q):
  for k in range(l[j],r[j]):
    if s[k]=="A" and s[k+1]=="C":
      ans+=1
    else:
      ans+=0
  x.append(ans)
  ans=0
  
for m in range(0,q):
  print(x[m])
      
      
      
  
  
  
  


Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n-1):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])

Buggy python submission (verdict: Runtime Error):
n,q=map(int(input()).split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[]
for i in range(q):
  x1,y1=[int(i) for i in input().split()]
  x.append(x1)
  y.append(y1)
  
for j in range(0,q):
  for k in range(l[j],r[j]):
    if s[k]=="A" and s[k+1]=="C":
      ans+=1
    else:
      ans+=0
  x.append(ans)
  ans=0
  
for m in range(0,q):
  print(x[m])
      
      
      
  
  
  
  

Fixed submission:
n,q=map(int,input().split())
s=list(str(input()))
l=[]
r=[]
ans=0
x=[0]
for i in range(q):
  l1,r1=map(int,input().split())
  l.append(l1)
  r.append(r1)

for j in range(0,n-1):
  if s[j]=="A" and s[j+1]=="C":
    ans+=1
    x.append(ans)
  else:
    x.append(ans)

for k in range(0,q):
  print(x[r[k]-1]-x[l[k]-1])