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)
    begin_i,end_i = gets.chomp.split(" ").map(&:to_i)
    test_string = S.slice(begin_i-1,end_i-1)
    deleted_string = test_string.gsub("AC","")
    count = (test_string.length - deleted_string.length)/2
    puts count
end
