n, q = gets.chomp.split.map(&:to_i)
s = gets.chomp.split("")
q.times do
  cnt = 0
  route_a = 0
  l, r = gets.chomp.split.map(&:to_i)
  i = l - 1
  (r - l + 1).times do
    if route_a == 1
      if s[i] == "C"
        cnt += 1
        route_a = 0
      elsif s[i] != "A"
        route_a = 0
      end
    elsif s[i] == "A"
      route_a = 1
    end
    i += 1
  end
  puts cnt
end