Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			math, _ := strconv.Atoi(buf[0])
			english, _ := strconv.Atoi(buf[1])
			japanese, _ := strconv.Atoi(buf[2])
			if math == 100 || english == 100 || japanese == 100 {
				fmt.Println("A")
			} else if math + english >= 180 {
				fmt.Println("A")
			} else if math + english + japanese >= 240 {
				fmt.Println("A")
			} else if math + english + japanese >= 210 {
				fmt.Println("B")
			} else if math + english + japanese >= 150 && (math >= 80 || english >= 80) {
				fmt.Println("B")
			} else {
				fmt.Println("C")
			}
		}
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;

const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;


int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(!n) break;

        for(int i=0;i<n;i++){
            int pm,pe,pj;
            scanf("%d%d%d",&pm,&pe,&pj);
            int ave = (pm+pe+pj)/3;
            if((pm==100||pe==100||pj==100) || (pm+pe)/2>=90 || ave>=80){
                cout << "A" << endl;
            }else if(ave>=70 || (ave>=50&&(pm>=80||pe>=80))){
                cout << "B" << endl;
            }else{
                cout << "C" << endl;
            }
        }
    }

    return 0;
}

C++: #include <iostream>
using namespace	std;

int main() {
  int n, m, e, j;
  while(cin >> n, n) {
    for(int i = 0; i < n; i++) {
      cin >> m >> e >> j;
      if(m == 100 || e == 100 || j == 100)
	cout <<	"A" << endl;
      else if(m+e >= 180)
	cout << "A" << endl;
      else if(m+e+j >= 240)
	cout << "A" << endl;
      else if(m+e+j >= 210)
	cout << "B" << endl;
      else if(m+e+j >= 150 && (e >= 80 || m >= 80))
	cout << "B" << endl;
      else
	cout << "C" << endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
int main()
{
	int n,pm,pe,pj,i;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<n;i++){
		scanf("%d %d %d",&pm,&pe,&pj);
		if(pm==100||pe==100||pj==100){
			printf("A\n");
		}
		else if((pm+pe)/2>=90){
			printf("A\n");
		}
		else if((pm+pe+pj)/3>=80){
			printf("A\n");
		}
		else if((pm+pe+pj)/3>=70){
			printf("B\n");
		}
		else if((pm+pe+pj)/3>=50&&(pm>=80||pe>=80)){
			printf("B\n");
		}
		else{
			printf("C\n");
		}
		}
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,m,e,j,i,cls[10000],flg;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			flg=0;
			scanf("%d %d %d",&m,&e,&j);
			if(m==100||e==100||j==100){
				cls[i]=1;
				flg++;
			}
			if((m+e)/2>=90){
				cls[i]=1;
				flg++;
			}
			if((m+e+j)/3>=80){
				cls[i]=1;
				flg++;
			}
			if((m+e+j)/3>=70&&(m+e+j)/3<80){
				flg++;
				cls[i]=2;
			}
			if(((m+e+j)/3>=50&&(m+e+j)/3<80)&&((m>=80&&m<100)||(e>=80&&e<100))){
				flg++;
				cls[i]=2;
			}
			if(flg>=2){
				cls[i]=1;
			}
			if(flg<1){
				cls[i]=3;
			}
		}
		for(i=0;i<n;i++){
			if(cls[i]==1){
				printf("A\n");
			}
			if(cls[i]==2){
				printf("B\n");
			}
			if(cls[i]==3){
				printf("C\n");
			}

		}
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
    int n,pm,pe,pj,i,s,d;
	scanf("%d",&n);
	while(1){
	    if (n==0)  break;
		for (i=0;i<n;i++){
			scanf("%d %d %d",&pm,&pe,&pj);
			s=(pm+pe)/2.0;
			d=(pm+pe+pj)/3;
			if (pm==100||pe==100||pj==100){
				printf("A\n");
			}
			else if (s>=90||d>=80){
				printf("A\n");
			}
			else if (d>=70){
				printf("B\n");
			}
			else if (d>=50&&(pm>=80||pe>=80)){
				printf("B\n");
			}
			else {
				printf("C\n");
			}
		}
		return 0;
	}
	
}

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

C++: #include<iostream>
#define EPS 1e-10

using namespace std;


int main(){
  int n,A,B,C;
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      cin >> A >> B >> C;
      if(A == 100 || B == 100 || C == 100)cout << "A" << endl;
      else if((A+B)/2.0 >= 80+EPS)cout << "A" << endl;
      else if((A+B+C)/3.0 >= 70+EPS)cout << "B" << endl;
      else if((A+B+C)/3.0>=50+EPS && (A>=80 || B>=80))cout << "B" << endl;
      else cout << "C" << endl;
    }
  }
  return 0;
}

C++: #include<iostream>

int n,pm,pe,pj;

char solve(int m, int e, int j){
	char ans='C';
	if(m==100 || e==100 || j==100 || m+e>=180 || m+e+j>=240)
		ans = 'A';
	else if(m+e+j>=210 || (m+e+j>=50 && (m>=80 || e>=80)))
		ans = 'B';
	return ans;
}

int main(){
	while(true){
		std::cin >> n;
		if(!n)
			return 0;
		for(int i=0; i<n; i++){
			std::cin >> pm >> pe >> pj;
			std::cout << solve(pm, pe, pj);
		}
	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1};

int main() {
  int n;

  while(1) {
    cin >> n;
    if(!n) break;

    REP(i, n) {
      int pm, pe, pj;
      cin >> pm >> pe >> pj;
      if(pm == 100 || pe == 100 || pj == 100) cout << 'A' << endl;
      else if((pm+pe)/2 >=90) cout << 'A' << endl;
      else if((pm+pe+pj)/3 >= 80) cout << 'A' << endl;
      else if((pm+pe+pj)/3 >= 70) cout << 'B' << endl;
      else if(((pm+pe+pj)/3 >= 50) && (pm >= 80 || pe >= 80)) cout << 'B' << endl;
      else cout << 'C' << endl; 
    }
  }
}