count = STDIN.gets.split(' ')[1].to_i
s = STDIN.gets.chomp
count.times do |c|
    start = STDIN.gets.split(' ').map(&:to_i)
    str = s.slice(start[0] - 1..start[1] - 1)
    delete_l = str.delete('AC').length
    if delete_l == 0
        puts 0
    else
        puts (str.length - delete_l) / 2
    end
end
