n, q = gets.chomp.split.map(&:to_i)
s = gets.chomp.split('')
max = Array.new(s.length+1, 0);

(s.length - 1).times do |i|
  if s[i] == 'A' && s[i+1] == 'C'
    max[i] = 1
  end
end
q.times do |i|
  a, b = gets.chomp.split.map{|j| j.to_i - 1}
  z = 0
  if s[a] == 'C' && (a - 1 >= 0 && s[a-1] == 'A')
    z -= 1
  end
  if s[b] == 'A' && (b + 2 > s.length && s[b+1] == 'C')
    z -= 1
  end
  p z + max[a..b].inject(:+).to_i
end