#include<bits/stdc++.h>
using namespace std;
char getClass(int m, int e, int j) {
	if (m == 100 || e == 100 || j == 100 || (m + e) / 2 >= 90
			|| (m + e + j) / 3 >= 80)
		return 'A';
	if ((m + e + j) / 3 >= 70 || (m + e + j) / 3 >= 50 && m >= 80 || e >= 80)
		return 'B';
	return 'C';
}
int main() {
	int n, pm, pe, pj;
	while (cin >> n && n) {
		for (int i = 0; i < n; i++) {
			cin >> pm >> pe >> pj;
			cout << getClass(pm, pe, pj) << endl;
		}
	}
	return 0;
}
#include <stdio.h>

int dividing(int math, int english, int japanese)
{
	if (math == 100 || english == 100 || japanese == 100) {
		printf("A\n");
	}else if (math + english >= 180) {
		printf("A\n");
	}else if (math + english + japanese >= 240) {
		printf("A\n");
	} else if (math + english + japanese >= 210) {
		printf("B\n");
	} else if (math + english + japanese >= 150 && math >= 80) {
		printf("B\n");
	} else if (math + english + japanese >= 150 && english >= 80) {
		printf("B\n");
	} else {
		printf("C\n");
	}
}

int main(void)
{
	while (1) {
		int number;
		scanf("%d", &number);
		if (number == 0) {
			break;
		}
		for (int i = 0; i < number; i++) {
			int math;
			int english;
			int japanese;
			scanf("%d %d %d", &math, &english, &japanese);
			dividing(math, english, japanese);
		}
	}
}