until (n = gets.to_i).zero?
  n.times do
    p = gets.split.map(&:to_i)
    
    avg = p.inject(:+) / 3.0
    
    if p.include?(100) || (p[0] + p[1]) / 2 >= 90 || avg >= 80
      puts "A"
    elsif avg >= 70 || (avg >= 50 && (p[0] >= 80 || p[1] >= 80))
      puts "B"
    else  
      puts "C"
    end
  end
end