N,Q = gets.chomp.split(" ").map(&:to_i)
S = gets.chomp.to_s
test_range_list = []
Q.times do |i|
    test_range_list << gets.chomp.split(" ").map(&:to_i)
end

test_range_list.each do |range|
    count = 0
    test_string = S.slice(range[0]-1,range[1]-1)
    while test_string.include?("AC") do
        test_string.sub!("AC","")
        count += 1
    end
    puts count
end
