def grade score
  avg = score.inject(:+) / score.size
  if score.include?(100) || (score[0] + score[1]) / 2 >= 90 || avg >= 80
    "A"
  elsif avg >= 70 || (avg >= 50 && (score[0] >= 80 || score[1] >= 80))
    "B"
  else
    "C"
  end
end

while (n = $stdin.gets.to_i) != 0 do
  n.times do
    puts grade($stdin.gets.chomp.split(" ").map(&:to_i))
  end
end