#include<stdio.h>

void devide(int x, int y, int z)
{
    if((x == 100) || (y == 100) || (z == 100)) {
        printf("A\n");
    } else if ((x + y) >= 90*2) {
        printf("A\n");
    } else if ((x + y + z) >= 80*3) {
        printf("A\n");
    } else if ((x + y + z) >= 70*3) {
        printf("B\n");
    } else if ((x + y + z) >= 50*3) {
        if ((x >= 80) || (y >= 80)){
            printf("B\n");
        } else {
            printf("C\n");
        }
    } else {
        printf("C\n");
    }
}

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

    scanf("%d", &num);

    while (num != 0) {
        for (int i = 0; i < num; i++) {
            scanf("%d %d %d", &pm, &pe, &pj);
            devide(pm, pe, pj);
        }

        scanf("%d", &num);
    }

    return 0;
}
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

static const double eps = 1e-8;

int getAvr(int* p,int n){
	int sum = 0;
	for(int i=0;i<n;i++){
		sum += p[i];
	}

	return sum/3;
}

int main(){
	int n;	
	while(~scanf("%d",&n)){	
		if(n==0) break;
		
		for(int i=0;i<n;i++){
			int p[3];
			//math,english,japanese			
			scanf("%d %d %d",p,p+1,p+2);

			for(int i=0;i<3;i++){
				if(p[i]==100){
					printf("A\n");
					goto next;
				}
			}

			if(p[0] + p[1] >= 180 || getAvr(p,3) >= 80){
				printf("A\n");
			}

			else if(getAvr(p,3) >= 70
				|| (getAvr(p,3) >= 50 && (p[0] >= 80 || p[1] >= 80))){
				printf("B\n");
			}

			else{
				printf("C\n");
			}
next:;

		}
		
	}
}