n, q = gets.split.map(&:to_i)
s = gets.chomp
count_ac = [0]
s.each_char.with_index do |c, i|
  count_ac[i + 1] = count_ac[i]
  count_ac[i + 1] += 1 if 0 < i &&  c == 'C' && s[i - 1] == 'A'
end

q.times do
  l, r = gets.split.map(&:to_i)
  puts count_ac[r] - count_ac[l]
end
