n, q = gets.split.map(&:to_i)
s = gets.chomp
lr =
  q.times.map do |i|
    gets.split.map(&:to_i)
  end

q.times.map do |i|
  l = lr[i][0]
  r = lr[i][1]
  str = s[(l-1)..(r-1)]
  puts str.scan(/AC/).size
end