N, Q = gets.split.map(&:to_i)
S = gets.chomp
ls = Array.new(Q)
rs = Array.new(Q)

Q.times do |i|
  ac_n = 0

  ls[i], rs[i] = gets.split.map(&:to_i)
  s = S.slice(ls[i] - 1, rs[i] - ls[i] + 1)

  (s.length - 1).times do |j|
    if(s[j] == "A" && s[j+1] == "C")
      ac_n += 1      
    end
    
  end
  puts ac_n
end
