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<string>
using namespace std;
int main()
{
	int n;
	int m[100] = {};
	int e[100] = {};
	int j[100] = {};
	char* rank[10000] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> m[i] >> e[i] >> j[i];
	}
	for (int i = 0; i < n; i++) {
		int s = (m[i] + e[i] + j[i]) / 3;
		if ((m[i] || e[i] || j[i]) == 100) {
			rank[i] = "A";
		}
		else if ((m[i] + e[i]) / 2 >= 90) {
			rank[i] = "A";
		}
		else if (s >= 80) {
			rank[i] = "A";
 		}
		else if (s >= 70) {
			rank[i] = "B";
		}
		else if (s >= 50 && m[i] >= 80) {
			rank[i] = "B";
		}
		else {
			rank[i] = "C";
		}
		cout << rank[i] << endl;
	}

	
	return 0;
	
}

C++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		for(int i=0; i<n; i++){
			int pm, pe, pj;
			cin >> pm >> pe >> pj;

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

	return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>

int gradeStudents(int pm, int pe, int pj);

int main(void)
{
    int number;
    int pm, pe, pj;
    while (true) {
        scanf("%d", &number);
        if (number == 0) {
            break;
        }
        for (int i = 0; i < number; ++i) {
            scanf("%d %d %d", &pm, &pe, &pj);
            printf("%c\n", gradeStudents(pm, pe, pj));
        }
    }
    return 0;
}

int gradeStudents(int pm, int pe, int pj)
{
    char result;
    if (pm == 100 || pe == 100 || pj == 100) {
        result = 'A';
    } else if ((pm + pe) / 2 >=90) {
        result = 'A';
    } else if ((pm + pe + pj) / 3 >= 80) {
        result = 'A';
    } else if ((pm + pe + pj) / 3 >= 70) {
        result = 'B';
    } else if ((pm + pe + pj) / 3 >= 50 && (pm >= 80 || pe >= 80)) {
        result = 'B';
    } else {
        result = 'C';
    }
    return result;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int pm,pe,pj,pa,cl;
  int i=0;
  char a[100000];
  
  while(cin>>cl!=0){
    for(int j=0;j<cl;j++){
      cin>>pm>>pe>>pj;
      pa=(pm+pe+pj)/3;
      if(pm==100||pe==100||pj==100||90<=(pm+pe)/2||80<=pa)a[i]='A';
      else if(70<=pa||80<=pe||80<=pm)a[i]='B';
      else a[i]='C';
      i++;
    }
  }
  
  for(int j=0;j<i;j++)
    cout<<a[j]<<endl;
  
  return 0;
}

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

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

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( (m+e)/2 >= 90 )
				cout << "A" << endl;
			else if( (m+e+j)/3 >= 80 )
				cout << "A" << endl;
			else if( (m+e+j)/3 >= 70 )
				cout << "B" << endl;
			else if( (m+e+j)/3 >= 50 && (m>=80 || e>=80) )
				cout << "B" << endl;
			else
				cout << "C" << endl;
		}
	}
	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((pe+pj+pm)/3>=80){
				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{
				cout<<"C"<<endl;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
char hyakuten(int students[][3],int n){
  for(int i=0;i<3;i++){
   if(students[n][i]==100)return 'A';
  }
  if((students[n][0]+students[n][1])/2>=90)return 'A';
  if((students[n][0]+students[n][1]+students[n][2])/3>=80)return 'A';
  if((students[n][0]+students[n][1]+students[n][2])/3>=70)return 'B';
  if((students[n][0]+students[n][1]+students[n][2])/3>=50&&students[n][0]>=80||students[n][1]>=80)return 'B';
  return 'C';
}


int main(){
  int n;
  while(cin>>n&&n){
    int students[10000][3];
    for(int i=0;i<n;i++){
      for(int j=0;j<3;j++){
        cin>>students[i][j];
      }
    }
    for(int i=0;i<n;i++){
      cout<<hyakuten(students[i],i)<<endl;
    }
  }
  return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

int f(int m, int e, int j) {
  if (m == 100 || e == 100 || j == 100) return 0;
  if (m + e >= 90 * 2) return 0;
  if (m + e + j >= 80 * 3) return 0;
  if (m + e + j >= 70 * 3) return 1;
  if (m + e + j >= 50 * 3 && (m >= 80 || e >= 80)) return 1;
  return 2;
}

void solve() {
  int n;
  while (cin >> n, n) {
    while (n--) {
      int m, e, j;
      cin >> m >> e >> j;
      cout << char('A' + f(m, e, j)) << endl;
    }
  }
}

C++: #include<stdio.h>
int main(void)
{
	int n,m,e,j,i,cls[10000],flg;
	while(1){
		scanf("%d",&n);
		if(n<1)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){
				cls[i]=2;
				flg++;
			}
			if((m+e+j)/3>=50&&(m>=80||e>=80)){
				cls[i]=2;
				flg++;
			}
			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;
}