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++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	while (true) {
		int n; cin >> n;
		if (n == 0)break;

		rep(i, n) {
			int a, b, c; cin >> a >> b >> c;
			char ans;

			if ((a == 100 || b == 100 || c == 100) || (a + b >= 180) || (a + b + c >= 240))ans = 'A';
			else if ((a + b + c >= 210) || (a + b + c >= 150 && (a >= 80 || b >= 80)))ans = 'B';
			else ans = 'C';

			Cout(ans);
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n!=0){
    int a,b,c;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      if(a==100||b==100||c==100||(a+b)/2>=90||(a+b+c)/3>=80){
	cout<<'A'<<endl;
      }else if((a+b+c)/3>=70||((a+b+c)/3>=50&&(a>=80||b>=80))){
	cout<<'B'<<endl;
      }else{
	cout<<'C'<<endl;
      }	
    }
    cin>>n;
  }
  return 0;
}

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



int main(){
  //構造体
  struct test{
    int Math;
    int English;
    int Japanese;
  };

  int n,total;
  test student;

  while(1){

    char rank='A';
    total=0;
    // cout << "test" << endl;
    cin >> n;
    if(n==0)break;

    for(int i=0;i<n;i++){
      //   cout << "test Math English Japanese" << endl;
      while(1){
	cin >> student.Math >> student.English >> student.Japanese;
	if(student.Math==100||student.English==100||student.Japanese==100)break;
	total=student.Math+student.English;
	total=total/2;
	if(total>=90)break;
	total=student.Math+student.English+student.Japanese;
	total=total/3;
	if(total>=80)break;
	
	rank='B';
	if(total>=70)break;
	if(total>=50&&(student.Math>=80||student.English>=80))break;
	
	rank='C';
	if(1)break;
      }
      cout << rank << endl;
    }
  }
}

C++: // 2011/02/16 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		// üÍi¶kÌlj
		int n;
		cin >> n;
		if(n==0)
			break;

		// üÍi¶kÌ_jÆ»f
		for(int i=0; i<n; i++){
			int pm, pe, pj;
			cin >> pm >> pe >> pj;
			if(pm==100||pe==100||pj==100)		// 100_ÌÈÚª é
				cout << 'A' << endl;
			else if((pm+pe)/2>=90)			// wÆpêÌ½Ï_ª90_Èã
				cout << 'A' << endl;
			else if((pm+pe+pj)/3>=80)		// 3ÈÚÌ½Ï_ª80_Èã
				cout << 'A' << endl;
			else if((pm+pe+pj)/3>=70)		// 3ÈÚÌ½Ï_ª70_Èã
				cout << 'B' << endl;
			else if(((pm+pe+pj)/3>=50)&&(pm>=80||pe>=80))		// 3ÈÚÌ½Ï_ª50_ÈãÅw©pêª80_Èã
				cout << 'B' << endl;
			else					// ãÌðð½³È¢
				cout << 'C' << endl;
		}
	}

	return 0;
}

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

int main(void)
{
  while (true)
  {
    int n;
    cin >> n;
    if ( n == 0 ) break;

    for (int i = 0; i < n; ++i)
    {
      int math, englith, japanese;
      cin >> math >> englith >> japanese;

      if (math == 100 or englith == 100 or japanese == 100
          or 180 <= math + englith
          or 240 <= math + englith + japanese)
      {
        cout << 'A' << endl;
      }
      else if (210 <= math + englith + japanese
               or (150 <= math + englith + japanese 
                   and ( 80 <= math or 80 <= englith )
                  )
              )
      {
        cout << 'B' << endl;
      }
      else
      {
        cout << 'C' << endl;
      }
    }
  }
  return 0;
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0218

int main() {
	int n;
	while (cin >> n) {
		for (int i = 0; i < n; i++) {
			int m, e, j;
			cin >> m >> e >> j;
			int avg = (m + e + j) / 3;
			if (m == 100 || e == 100 || j == 100) cout << "A";
			else if ((m + e) / 2 >= 90) cout << "A";
			else if (avg >= 80) cout << "A";
			else if (avg >= 70) cout << "B";
			else if (avg >= 50 && (m >= 80 || e >= 80)) cout << "B";
			else cout << "C";
			cout << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>

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 >= 80)cout << "A" << endl;
      else if((A+B+C)/3 >= 70)cout << "B" << endl;
      else if((A+B+C)/3>=50 && (A>=80 || B>=80))cout << "B" << endl;
      else cout << "C" << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

int main(void){

  int n,pm,pe,pj;

  while(cin >> n,n){
    while(n--){
      cin >> 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;
	continue;
      }
      
      if(ave>=70 || (ave>=50 && (pm>=80 || pe>=80))){
	cout << "B" << endl;
	continue;
      }
      
      cout << "C" << endl;
    }
  }
  
  return 0;
}

C++: #include <iostream>


char classdiv(int pm, int pe, int pj)
{
	double ave = (pm + pe + pj) / 3;
	if (pm == 100 || pe == 100 || pj == 100) {
		return 'A';
	} else if ((pm + pe) / 2 >= 90 || ave >= 80) {
		return 'A';
    } else if ( ave >= 70) {
		return 'B';
	} else if (ave >= 50 && (pm >= 80 || pe >= 80)) {
		return 'B';
	} else {
		return 'C';
	}
}
int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n == 0) {
			break;
		} else {
	        for (int i = 0; i < n; i++) {
		        int pm;
		        int pe;
		        int pj;
		        std::cin >> pm >> pe >> pj;
				std::cout << classdiv(pm, pe, pj) << std::endl;
			}
		}
	}
	return 0;
}