#! /bin/ruby

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

q.times do |j|
  l, r = gets.chomp.split(" ").map(&:to_i)
  candidate = ""
  cnt = 0
  l.upto(r) do |i|
    c = chars[i-1]
    if candidate == 'A' && c == 'C'
      cnt+=1
      candidate = ""
    elsif candidate == "" && c == 'A'
      candidate = 'A'
    else
      candidate = ""
    end
  end
  puts cnt
end