N, Q = gets.split(' ').map(&:to_i)
S = gets

Q.times do
  l = gets.split(' ').map(&:to_i)
  s = S[(l[0]-1)..(l[1]-1)]
  slen = s.length
  if s.include?('AC')
    s.gsub!('AC', '')
  end
  puts (slen - s.length) / 2
end
