n, i = gets.split.map(&:to_i)
text = gets.chomp

i.times do
    max = 0
    s, e = gets.split.map(&:to_i)
    
    (s-1..e-2).each do |j|
        max += 1 if text[j] == 'A' and text[j+1] == 'C'
    end
    p max
end