import Control.Monad

main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n getLine
      let ls' = map (map read . words) ls
          ansL = map rank ls'
      mapM_ putStrLn ansL
      main

rank :: [Int] -> String
rank [m,e,j]
  | (elem 100 [m,e,j]) || 90 <= aveME || 80 <= aveAll = "A"
  | 70 <= aveAll || (50 <= aveAll && (80 <= m || 80 <= e)) = "B"
  | otherwise = "C"
  where
    aveAll = (m+e+j) `div` 3
    aveME = (m+e) `div` 2