n, q = gets.split.map(&:to_i)
s = gets.chomp

at = []
(0..s.length - 2).each do |i|
  at << i + 1 if s[i] == 'A' && s[i + 1] == 'C'
end

results = q.times.map do
  l, r = gets.split.map(&:to_i)

  at.select {|a| l <= a && a < r }.count
end
puts results
