n,q=io.read():match("(.+)%s(.+)")
s=io.read()
pre=nil
count={[0]=0}
ix=0
for i in s:gmatch(".")do
  if pre=="A" and i=="C" then
    count[ix+1]=count[ix]+1
  else
    count[ix+1]=count[ix]
  end
  pre=i
  ix=ix+1
end
for i=1,q do
  l,r=io.read():match("(.+)%s(.+)")
  print(count[r*1]-count[l*1])
end