loop do
    n = gets.to_i
    break if n == 0
    n.times do
        points = gets.split.map(&:to_i)
        avg = points.inject(:+) / 3
        if points.any? {|x| x == 100} || points[0..1].inject(:+) / 2 >= 90 || avg >= 80
            puts ?A
        elsif avg >= 70 || (avg >= 50 && points[0..1].any?{|x| x >= 80})
            puts ?B
        else
            puts ?C
        end
    end
end
