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

  def self.read1
    gets.chomp.split.map(&:to_i)
  end
  def self.read2
    gets.chomp
  end
  def self.read3(n)
    n.times.map{read1}.transpose
  end
end

Main.main
