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>
using namespace std;

int main()
{
  int n, m, e, j;
  while(1)
  {
    cin >> n;
    if(!n)
      break;

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

C++: #include<stdio.h>

//this file is not a C file but a C++ file                                      

int main(void){
    int stnum;//the number of the student                                       
    int pm, pe, pj;//ある生徒の点数                                             
    char grade;//成績                                                           
    while(1) {
        scanf(" %d", &stnum);
        if(stnum == 0) {
            break;
        }
        for(int i = stnum - 1;i >= 0;i -= 1) {
            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);
        }
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
const int INF = INT_MAX / 2;

typedef long long ll;

int N;
ll d[10], v[10];

ll GCD(ll a, ll b)
{
	if(b == 0) return a;
	return GCD(b, a % b);
}

ll LCM(ll a, ll b)
{
	return a / GCD(a, b) * b;
}

int main(){
	while(cin >> N, N)
	{
		int M, E, J;
		for(int i = 0; i < N; i++)
		{
			cin >> M >> E >> J;
			char ans;
			if(M == 100 || E == 100 || J == 100) ans = 'A';
			else if((M + E) / 2 >= 90) ans = 'A';
			else if((M + E + J) / 3 >= 80) ans = 'A';
			else if((M + E + J) / 3 >= 70) ans = 'B';
			else if((M + E + J) / 3 >= 50 && (M >= 80 || E >= 80)) ans = 'B';
			else ans = 'C';
			printf("%c\n", ans);
		}
	}
	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||(m+e)/2>=90||(m+e+j)/3>=80){
				cls[i]=1;
				flg=1;
			}
			if((m+e+j)/3>=70){
				flg++;
				cls[i]=2;
			}
			if((m+e+j)/3>=50&&(m>=80||e>=80)){
				flg++;
				cls[i]=2;
			}
			if(flg>=2){
				cls[i]=1;
			}
			if(flg==0){
				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++: // 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, m;
  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 divide(int, int, int);

int main(void)
{
	int n;
	scanf("%d", &n);
	int grade[n][3];
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &grade[i][0], &grade[i][1], &grade[i][2]);
		divide(grade[i][0], grade[i][1], grade[i][2]);
	}
	return 0;
}

int divide(int m, int e, int j)
{
	if (m == 100 || e == 100 || j == 100 ||
		(m + e) / 2 >= 90 ||
		(m + e + j) / 3 >= 80) {
		printf("A\n");
	} else if ((m + e + j) / 3 >= 70 ||
		       ((m + e + j) / 3 >= 70 && (m > 80 || e > 80))) {
		printf("B\n");
	} else {
		printf("C\n");
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,a,b,c,i;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%d %d %d",&a,&b,&c);
			if(a==100 || b==100 || c==100 || (a+b)/2>89 || (a+b+c)/3>79)  printf("A\n");
			else if((a+b+c)/3>69 && (a+b+c)/3>49 && a>79 || b>79)  printf("A\n");
			else if((a+b+c)/3>69 || (a+b+c)/3>49 && a>79 || b>79)  printf("B\n");
			else printf("C\n");
		}
		scanf("%d",&n);
	}
	return 0;
}

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

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

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

using namespace std;

int main() {
	int n, math, english, japanese, ave;

	while (cin >> n, n) {
		for (int i = 0; i < n; ++i) {
			cin >> math >> english >> japanese;
			if (math == 100 || english == 100 | japanese == 100) {
				cout << "A" << endl;
				continue;
			}
			if (((math + english) / 2) >= 90) {
				cout << "A" << endl;
				continue;
			}

			ave = (math + english + japanese) / 3;
			if (ave >= 80) {
				cout << "A" << endl;
			}
			else if (ave >= 70) {
				cout << "B" << endl;
			}
			else if (ave >= 50 && (math >= 80 || english >= 80)) {
				cout << "B" << endl;
			}
			else {
				cout << "C" << endl;
			}
		}
	}

	return 0;
}