#include <iostream>
#include <stdio.h>

char judge(int, int, int);

int main() 
{
	int pm, pe, pj;
	int number;
	
	while (true) {
		std::cin >> number;
		
		if (number == 0) {
			break;
		}
		
		for (int i = 0; i < number; i++) {
			std::cin >> pm >> pe >> pj;
			std::cout << judge(pm, pe, pj) <<std::endl;
		}
	}
	return 0;
}

char judge(int pm, int pe, int pj) {
	int avarage = (pm + pe + pj) /3;
	
	if  (pm == 100 || pe == 100 || pj == 100) {
		return 'A';
	} else if ((pm + pe) / 2 >= 90 || avarage >= 80) {
		return 'A' ;
	} else if (avarage >= 70) {
		return 'B';
	} else if (avarage >= 50 && (pm >= 80 || pe >= 80)) {
		return 'B';
	} else {
		return 'C';
	}
}
#include <iostream>
#include <vector>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.divstudent", "r", stdin );
	const char rank[] = { 'A', 'B', 'C' };
	int n;

	while (cin >> n && n ){
		vector <vector <int> > s(n, vector <int> (3, 0 ) );

		for (int i = 0; i < n; ++i){
			for (int j = 0; j < 3; ++j){
				cin >> s[i][j];	// pm, pe, pj order
			} // end for
		} // end for
/*
100 _ÌÈÚª é	 A
wÆpêÌ½Ï_ª 90 _Èã	 A
3 ÈÚÌ½Ï_ª 80 _Èã	 A
3 ÈÚÌ½Ï_ª 70 _Èã	 B
3 ÈÚÌ½Ï_ª 50 _ÈãÅw©pêª 80 _Èã	 B
ãÌðð½³È¢	 C
¡Ìðð½·êÍAæèxÌ¢NXÉª¯çêÜ·B
*/
		for (int i = 0; i < n; ++i){

			double me  = (s[i][0] + s[i][1])/2.;
			double avg = (s[i][0] + s[i][1] + s[i][2])/3.;
 	
			if ( s[i][0] == 100 || s[i][1] == 100 || s[i][2] == 100
			|| me >= 90.0 || avg >= 80. ) {
				cout << rank[0] << endl;
				continue;
			} // end if
			if ( avg >= 70. || (avg >= 50. && (s[i][0] >= 80 || s[i][1] >= 80 ) ) ) {
				cout << rank[1] << endl;
				continue;
			} // end if

			cout << rank[2] << endl;
		} // end for
	} // end loop
		
	return 0;
}