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

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