import scala.io.StdIn.{readInt,readLine}

object Main extends App {
  def eval(math:Int,eng:Int,jp:Int) = {
    if(math == 100 || eng == 100 || jp == 100) "A"
    else if((math+eng)/2 >= 90) "A"
    else if((math+eng+jp)/3 >= 80) "A"
    else if((math+eng+jp)/3 >= 70) "B"
    else if((math+eng+jp)/3 >= 50 && (math >= 80 || eng >= 80)) "B"
    else "C"
  }

  println {
    Iterator.continually(readInt).takeWhile(_ != 0).map { n =>
      {
        for(i<- 1 to n) yield {
          val score = readLine.split(" ").map(_.toInt)
          eval(score(0),score(1),score(2))
        }
      }.mkString("\n")
    }.mkString("\n")
  }
}