gets
s = gets.chomp

idx = 0
pos = []
ac = nil
s.each_char do |c|
    if ac
        if c == "C"
            pos.push(idx - 1)
            ac = nil
        end
    else
        if c == "A"
            ac = c
        end
    end
    idx += 1
end

while line = gets
    l, r = line.chomp.split(/\s/).map{|i| i.to_i - 1}
    puts pos.select{|i| l <= i and r > i}.size
end
