c_l, q_l = gets.split.map(&:chomp).map(&:to_i)
string = gets.split('').map(&:chomp)

q_l.times do
  count = 0
  s, e = gets.split.map(&:chomp).map(&:to_i)
  truncated_string = string[(s-1)..(e-1)]
  truncated_string.each_with_index do |c, i|
    if c != 'A'
      next     
    end
    
    if  (s - 1) + (i + 1) < e && truncated_string[i+1] = 'C'
      count += 1
    end
  end
  puts count
end