let () =
  let f (m,e,j) =
    if m = 100 || e = 100 || j = 100 then "A"
    else if (m+e)/2 >= 90 then "A"
    else if (m+e+j)/3 >= 80 then "A"
    else if (m+e+j)/3 >= 70 then "B"
    else if (m+e+j)/3 >= 50 && (m >= 80 || e >= 80) then "B"
    else "C"
  in
  let rec read () =
    let n = Scanf.scanf "%d\n" (fun x -> x) in
    if n = 0 then ()
    else
      begin
        let rec loop = function
            0 -> ()
          | i ->
             let score = Scanf.scanf " %d %d %d\n" (fun x y z->(x,y,z)) in
             Printf.printf "%s\n" (f score);
             loop (i-1)
        in loop n; read ()
      end
  in read ()
;;