#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int n, a, b, c;
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) {
            scanf("%d %d %d", &a, &b, &c);
            if ((a == 100 || b == 100 || c == 100) || ((a + b)/2 >= 90) || ((a+b+c)/3 >= 80)) printf("A\n");
            else if (((a+b+c)/3 >= 70) || ((a+b+c)/3 >= 50 && (a >= 80 || b >= 80))) printf("B\n");
            else printf("C\n");
        }
    }
    return 0;
}

