N, Q = gets.split(' ').map(&:to_i)
S = gets.chomp

ac = Array.new
S.size.times do |i|
  if i == 0
    ac[0] = 0
  elsif S[i] == 'C' && S[i-1] == 'A'
    ac[i] = ac[i-1] + 1
  else
    ac[i] = ac[i-1]
  end
end

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