n, qs = gets.split(' ').map(&:to_i)
x = []
s = gets.to_s
qs.times { |q| x << gets.split(' ').map(&:to_i) }
x.each do |q|
  ss = s[(q[0] - 1)..(q[1] - 1)]
  count = 0
  while index != -1
    index = ss.index('AC')
    ss[index..index + 1] == '**'
    count += 1
  end
  puts count
end
