import Control.Applicative
import Control.Monad

data Class = A | B | C deriving(Show)

divideClass :: [[Int]] -> [Class]
divideClass [] = []
divideClass ([]:_) = []
divideClass ([_]:_) = []
divideClass ([_, _]:_) = []
divideClass ((m:e:j:_):xs) =
  let cand1 = (m == 100) || (e == 100) || (j == 100)
      cand2 = (m + e) >= 180
      cand3 = (m + e + j) >= 240
      cand4 = (m + e + j) >= 210
      cand5 = (m + e + j >= 150) && (m >= 80 || e >= 80)
  in
      if cand1 || cand2 || cand3
        then A : divideClass xs
        else if cand4 || cand5
          then B : divideClass xs
          else
            C : divideClass xs



main :: IO()
main = do
  n <- (read :: String -> Int) <$> getLine
  unless (n == 0) $ do
    line <- map (map (read :: String -> Int) . words) <$> replicateM n getLine
    mapM_ print $ divideClass line
    main