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

accum = []
accum[0] = 0
1.upto(S.size - 1) do |i|
  if (S[i - 1] + S[i]) == 'AC'
    accum[i] = accum[i - 1] + 1
  else
    accum[i] = accum[i - 1]
  end
end

# p accum

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