N, Q=gets.split.map(&:to_i)
S=gets.chomp
lrs=Q.times.map { gets.split.map(&:to_i) }

lrs.each do |lr|
  cnt=0
  str = S[(lr[0]-1), (lr[1]-1)]
  ((str.size)-1).times do |i|
    if str[i] == "A" || str[i+1] == "C"
      cnt+=1
    end
  end
  p cnt
end
