n,q = $stdin.gets.split.map(&:to_i)
s = $stdin.gets.chomp
result = []

n.times do |i|
  if s[i]=='A'
    if !s[i+1].nil? && s[i+1]=='C'
      result[i]=1
    end
  end
end

q.times do
  l,r = $stdin.gets.split.map(&:to_i)
  puts result[l-1..r-2].count(1)
end
