config = gets
target = gets.slice(0, config.split[0].to_i)

def to_count_array(target, countee)
  count = 0
  index_array = Array.new(target.size) do |offset|
    count += 1 if target.index(countee, offset) == offset
    count
  end
  index_array.unshift 0
  return index_array
end

ac_indexes = to_count_array(target, "AC")

config.split[1].to_i.times do
  range = gets
  exit if !range

  from, to = range.split.map(&:to_i)
  puts ac_indexes[to-1] - ac_indexes[from-1]
end
