string_len, question_num = STDIN.gets.split.map(&:to_i)
question_str = STDIN.gets.chomp

index = [0] * (string_len + 1)

(question_str.size - 1).times do |i|
  if question_str.slice(i, 2) == 'AC'
    index[i + 1] = index[i] + 1
  else
    index[i + 1] = index[i]
  end
end

question_num.times do |_|
  l, r = STDIN.gets.split.map(&:to_i)
  STDOUT.puts index[r-1] - index[l-1]
end