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