#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#define rep(i,n) for(int i=0;i<(int)n;i++)

using namespace std;

string ten[3]={"A","B","C"};

int main()
{
	int n;
	cin>>n;
	for(;n!=0;cin>>n)
	{
		rep(i,n)
		{
			int ma,en,ja;
			int ans=2;
			cin>>ma>>en>>ja;
			
			if(((ma+en+ja)/3>=50&&(ma>=80||en>=80))||(ma+en+ja)/3>=70)ans=1;
			if((ma+en+ja)/3>=80||(ma+en)/2>=90||en==100||ja==100||ma==100)ans=0;
			
			cout<<ten[ans]<<endl;
		}
		
		
	}
}
#include<iostream>
using namespace std;
int main(void)
{
    int n,pm[10001],pe[10001],pj[10001];
    while(1){
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>pm[i]>>pe[i]>>pj[i];
        }
        for(int i=0;i<n;i++){
            if(pm[i]==100||pe[i]==100||pj[i]==100||(pm[i]+pe[i])/2>=90||(pm[i]+pe[i]+pj[i])/3>=80)
                cout<<"A\n";
            else if((pm[i]+pe[i]+pj[i])/3>=70)cout<<"B\n";
            else if((pm[i]>=80||pe[i]>=80)&&(pm[i]+pe[i]+pj[i])/3>=50)cout<<"B\n";
            else cout<<"C\n";
        }
    }
}