n, q = gets.split.map(&:to_i)
str  = gets.chomp.chars
cnt  = Array.new(n, 0)

(n - 1).times do |i|
  if [str[i], str[i + 1]] == ['A', 'C']
    cnt[i + 1] = cnt[i] + 1
  else
    cnt[i + 1] = cnt[i]
  end
end

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