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<stdio.h>

//this file is not a C file but a C++ file                                      
void seisekiduke(void);//宣言                                                   

int main(void){
    int stnum;//the number of the student                                       
    while(1) {
        scanf(" %d", &stnum);
        if(stnum == 0) {
            break;
        }
        for(int i = stnum - 1;i >= 0;i -= 1) {
            seisekiduke();//一名の生徒の成績を付ける                            
        }
    }
    return 0;
}

void seisekiduke(void) {
    int pm, pe, pj = 0;//score                                                  
    char grade;
     scanf(" %d %d %d", &pm, &pe, &pj);
        if((pm == 100 || pe == 100 || pj == 100) ||
           (pm + pe) / 2 >= 90                   ||
           (pm + pe + pj) / 3 >= 80) {
           grade = 'A';
        }else if((pm + pe + pj) / 3 >= 70 ||
                (((pm + pe + pj) / 3 >= 50) && (pm >= 80 || pe >= 80))){
            grade = 'B';
        }else{
            grade = 'C';
        }
        printf("%c\n", grade);

}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long int ll;

int main()
{
    for(;;){
		int n;
		cin >> n;
		if(n==0)return 0;
		for(int i=0;i<n;i++){
			int a,b,c;
			cin >> a >> b >> c;
			if(a==100||b==100||c==100)
				printf("A\n");
			else if(b+a>=180)
				printf("A\n");
			else if(a+b+c>=240)
				printf("A\n");
			else if(a+b+c>=210)
				printf("B\n");
			else if(a+b+c>=150&&(a>=80||b>=80))
				printf("B\n");
			else printf("C\n");
		}
	}
}

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

using namespace std;

typedef vector<int> VI;
typedef pair<int,int> PII;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        rep(i,n){
            int a,b,c;
            cin>>a>>b>>c;
            if(a==100 ||b==100 || c==100 || ((a+b+c)>=240) || a+b>=180){cout<<"A"<<endl;}
            else if(a+b+c>=210 || ((a+b+c>=150) && (a>=80 || b>=80) )){cout<<"B"<<endl;}
            else{cout<<"C"<<endl;}
            
        }
    }
    return 0;
}

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

main(){
	int n,p,pm,pe,pj ;
	while( cin >> n , n ){
		for( int i=0 ; i<n ; i++ ){
			cin >> pm >> pe >> pj ;
			double a = (pm+pe) / 2.0 ;
			double b = (pm+pe+pj) / 3.0 ;
			bool t = false ;
			if( pm >= 80 || pe >= 80 ) t = true ;
			
			if( pm==100 || pe==100 || pj==100 ) cout << "A" ;
			else if( a >= 90 ) cout << "A" ;
			else if( b >= 80 ) cout << "A" ;
			else if( b >= 70 ) cout << "B" ;
			else if( b >= 50 && t ) cout << "B" ;
			else cout << "C" ;
			
			cout << endl ;
		}
	}
}

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

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

C++: #include <iostream>
 
 
char dividing(int math, int english, int japanese)
{
    if (math == 100 || english == 100 || japanese == 100) {
        return 'A';
    } else if ((math + english) / 2 >= 90) {
        return 'A';
    } else if ((math + english + japanese) / 3 >= 80) {
        return 'A';
    } else if ((math + english + japanese) / 3 >= 70) {
        return 'B';
    } else if ((math + english + japanese) / 3 >= 50) {
        if (math >= 80 || english >= 80) {
            return 'B';
        } else {
            return 'C';
        }
    } else {
        return 'C';
    }
}
 
 
int main()
{
    int math, english, japanese, n;  //n:size of dataset
    std::cin >> n;
    while (n != 0) {
        for (int i = 0; i < n; i++) {
            std::cin >> math >> english >> japanese;
            std::cout << dividing(math, english, japanese) << std::endl;
        }
    }
    return 0;
}

C++: #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		rep(i, n){
			int m, e, j;
			scanf("%d%d%d", &m, &e, &j);
			
			char c;
			if(m==100 || e==100 || j==100 || m+e>=180 || m+e+j>=240)
				c = 'A';
			else if(m+e+j >= 210 || (m+e+j>=150 && (m>=80 || e>=80)))
				c = 'B';
			else
				c = 'C';
			printf("%c\n", c);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
 
int main() {
  int N;
  while(cin >>N && N){
    REP(i, N){
      int m, e, j; cin >>m >>e >>j;
      if(m == 100 || e == 100 || j == 100) cout <<"A" <<endl;
      else if(((double)m + e) / 2.0 >= 90) cout <<"A" <<endl;
      else if(((double)m + e + j) / 3.0 >= 80) cout <<"A" <<endl;
      else if(((double)m + e + j) / 3.0 >= 70) cout <<"B" <<endl;
      else if(((double)m + e + j) / 3.0 >= 50 && (m >= 80 || e >= 80)) cout <<"B" <<endl;
      else cout <<"C" <<endl;
    }
  }
  return 0;
}