n,m=gets.chomp.split(" ").map{|s| s.to_i}
s=gets.chomp.split("")
l,r=[],[]
for t in 0..m-1
  l[t],r[t]=gets.chomp.split(" ").map{|k| k.to_i}
end

for t in 0..m-1
  st=s.slice(l[t]-1..r[t]-1)
  c=0
  for k in 0..(r[t]-l[t]-1)
    if st[k]=="A" && st[k+1]=="C"
      c+=1
    end
  end
  puts c
end