#coding: euc-jp
class Main
  def self.main
    n, q = read1
    s = read2
    l, r = read3(q)
    ans = Array.new(q, 0)
    pos = 0
    (n - 1).times do |pos|
      if s[pos, 2] == 'AC' then
        q.times do |i|
          if (l[i] - 1) <= pos && pos <= (r[i] - 2) then
            ans[i] += 1
          end
        end
      end
    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
