while n = gets.to_i
  break if n.zero?
  data = []
  n.times do
    scores = gets.split.map(&:to_i)
    me_ave = scores[0,2].inject(&:+)/2.0
    ave = scores.inject(&:+)/3.0
    if scores.max == 100 || me_ave >= 90.0 || ave >= 80.0
      data << "A"
    elsif ave >= 70.0 || (ave >= 50 && scores[0,2].max >= 80)
      data << "B"
    else
      data << "C"
    end
  end
  puts data
end