#include <stdio.h>

#define MYSCAN scanf

int main(void){
	int n, pm, pe, pj;

	while (true){

		MYSCAN("%d", &n);
		if (n == 0){ break; }
		for (int i = 0; i < n; i++){
			MYSCAN("%d%d%d", &pm, &pe, &pj);
			if (pm == 100 || pe == 100 || pj == 100){
				printf("A\n");
			}
			else if (pm + pe >= 180){
				printf("A\n");
			}
			else if (pm + pe + pj >= 240){
				printf("A\n");
			}
			else if (pm + pe + pj >= 210){
				printf("B\n");
			}
			else if (pm + pe + pj >= 150 && (pm >= 80 || pe >= 80)){
				printf("B\n");
			}
			else{
				printf("C\n");
			}	
		}
	}	
	return 0;
}
#include <iostream>

using namespace std;

char divide(int m, int e, int j) {
    if (m == 100 || e == 100 || j == 100) return 'A';
    if ( (m+e)/2 >= 90 ) return 'A';
    if ( (m+e+j)/3 >= 80 ) return 'A';
    if ( (m+e+j)/3 >= 70 ) return 'B';
    if ( (m+e+j)/3 >= 50 && (m >= 80 || e >= 80) ) return 'B';
    return 'C';
}

int main() {
    int n;
    while (cin >> n, n) {
        while (n--) {
            int pm, pe, pj;
            cin >> pm >> pe >> pj;
            cout << divide(pm, pe, pj) << endl;
        }
    }
    return 0;
}