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

list = Array.new(N, 0)
i = 0
temp = ""
S.chars.each do |word|
    if i != 0 then
        if temp == "A" && word == "C" then
            list[i] = list[i - 1] + 1
        else
            list[i] = list[i - 1]
        end
    end
    temp = word
    i = i+1
end

Q.times do
    l, r = gets.split.map(&:to_i)
    puts list[r - 1] - list[l - 1]  
end
