#coding: euc-jp
class Main
  def self.main
    n, q = read1
    s = read2
    q.times do
      l, r = read1
      c = 0
      pos = l
      while pos < r
        a = /AC/ =~ s[(pos - 1)..(r - 1)]
        if a then
          c += 1
          pos += a + 2
        else
          pos = r
        end
      end
      puts c
    end
  end

  def self.read1
    gets.chomp.split.map(&:to_i)
  end
  def self.read2
    gets.chomp
  end
end

Main.main
