n,q=gets.split.map(&:to_i)
s=gets.chomp
lrs=[]
q.times{lrs << gets.split.map(&:to_i)}
acindex=[]
(n-1).times do |i|
  if s[i]=="A" && s[i+1]=="C"
    acindex.push(i+1)
  end
end
lrs.each do |lr|
  puts acindex.select{|n| lr[0]<=n && n<=lr[1]-1}.size
end
