#include<stdio.h>

//this file is not a C file but a C++ file                                      

int main(void){
    int stnum;//the number of the student                                       
    int pm, pe, pj;//ある生徒の点数                                             
    char grade;//成績                                                           
    while(1) {
        scanf(" %d", &stnum);
        if(stnum == 0) {
            break;
        }
        for(int i = stnum - 1;i >= 0;i -= 1) {
            scanf(" %d %d %d", &pm, &pe, &pj);
            if((pm == 100 || pe == 100 || pj == 100) ||
               (pm + pe) / 2 >= 90                   ||
               (pm + pe + pj) / 3 >= 80) {
                grade = 'A';
            }else if((pm + pe + pj) / 3 >= 70 ||
                     (((pm + pe + pj) / 3 >= 50) && (pm >= 80 || pe >= 80))){
                grade = 'B';
            }else{
                grade = 'C';
            }
            printf("%c\n", grade);
        }
    }
    return 0;
}
#include <iostream>

using namespace std;
 
void res(int, int, int);
 
int main()
{
    int n, pm, pe, pj;
 
    while (cin >> n, n) {
	for (int i = 0; i < n; i++) {
	    cin >> pm >> pe >> pj;
	    res(pm, pe, pj);
	}
    }
    return 0;
}
 
void res(int pm, int pe, int pj)
{
    double ave, meave;
 
    ave = (double)(pm + pe + pj) / 3;
    meave = (double)(pm + pe) / 2;
 
    if (pm == 100 || pe == 100 || pj == 100 || meave >= 90 || ave >= 80) {
	cout << 'A' << endl;
    } else if (ave >= 70 || ( ave >= 50 && ( pm >= 80 || pe >= 80))) {
	cout << 'B' << endl;
    } else {
        cout << 'C' << endl;
    }
}