
N, Q = gets.chomp.split(" ").map(&:to_i)
S = gets.chomp
Q.times do
  l, r = gets.chomp.split(" ").map(&:to_i)
  l -= 1
  r -= 1
  ix = l
  cnt = 0
  while (ix = S.index('AC', ix)) && ix < r
    ix += 2
    cnt += 1
  end
  puts cnt
end
