N, Q = gets.chomp().split(" ").map(&:to_i)
S = gets.chomp()
count = Array.new(Q)

Q.times do |num|
  l, r = gets.chomp().split(" ").map(&:to_i)
  partial_S = S.slice(l-1..r-1)
  count[num] = partial_S.scan("AC").length
end
puts count