N, Q = gets.chomp.split(' ').map(&:to_i)
S = gets.chomp
count_list = Array.new(N) { -1 }
count = 0
count_list[0] = count
(1..N).each do |i|
  prev = S[i - 1]
  ch = S[i]
  if prev == 'A' && ch == 'C'
    count += 1
  end
  count_list[i] = count
end

Q.times do
  l, r = gets.chomp.split(' ').map(&:to_i)
  # 1 to 0-origin
  l -= 1
  r -= 1
  puts count_list[r] - count_list[l]
end
