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 <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,n;
  while(1){
    cin >> n;
    int pm,pe,pj;
    if(n == 0) break;
    for(i=0;i<n;i++){
      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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,e,j;
  while(cin >> n&&n){
    rep(i,n){
      cin >> m >> e >> j;
      if(m == 100 || e == 100 || j == 100){
        cout << "A"<<endl;
        continue;
      }
      if((1.0*m+e)/2.0 >= 90){
        cout << "A"<<endl;
        continue;
      }
      if(1.0*(m+e+j)/3.0 >= 80){
        cout << "A"<<endl;
      }
      else if(1.0*(m+e+j)/3.0 >= 70) cout << "B"<<endl;
      else if(1.0*(m+e+j)/3.0 >= 50 && (m >= 80 || e >= 80)) cout << "B" << endl;
      else cout << "C" <<endl;
    }
  }
  return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

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

C++: #include <cstdio>


int n, sum, p[3];
bool f;

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

        for(int i = 0; i < n; i++){
            f = false;
            scanf("%d %d %d", &p[0], &p[1], &p[2]);
            sum = p[0] + p[1] + p[2];

            for(int j = 0; j < 3; j++)
            if(p[j] == 100){
                printf("A\n");
                f = true;
                break;
            }

            if(f) continue;
            if(p[0] + p[1] >= 180){
                printf("A\n");
                continue;
            }
            if(sum >= 240){
                printf("A\n");
                continue;
            }
            if(sum >= 210){
                printf("B\n");
                continue;
            }
            if(sum >= 150 && (p[0] >= 80 || p[1] >= 80)){
                printf("B\n");
                continue;
            }
            printf("C\n");

        }
    }


    return 0;
}

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

int middium(int mat,int ing, int jap){
	return (mat + ing + jap) / 3;
}


void classes(int mat,int ing,int jap){
	int mid;
	mid = middium(mat,ing,jap);

	if(mat == 100 || ing == 100 || jap == 100) cout <<  "A";
	else if((mat + ing)/2 >= 90)	cout << "A";
	else if(mid >= 80)	cout <<  "A";
	else if(mid	>= 70)	cout <<  "B";
	else if(mid >= 50 && (mat >= 80 || ing >= 80))	cout <<  "B";
	else	cout << "C";
}

int main(){
	int n,pm,pe,pj;
	char cla;

	while(cin >> n,n){
		for(int i=0;i<n;i++){
			cin >> pm >> pe >> pj;
			classes(pm,pe,pj);
			cout << endl;
		}
	}

	return 0;
}

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

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		for (int i = 0; i < N; ++i) {
			int m, e, j; cin >> m >> e >> j;
			int ans = 0;
			if (m == 100 || e == 100 || j == 100) {
				ans = 0;
			}
			else if (m + e >= 180)ans = 0;
			else if (m + e + j >= 240)ans = 0;
			else if (m + e + j >= 210)ans = 1;
			else if (m + e + j >= 150 && (m >= 80 || e >= 80))ans = 1;
			else ans = 2;
			if (ans == 0)cout << 'A' << endl;
			else if (ans == 1)cout << 'B' << endl;
			else cout << 'C' << endl;
		}
	}
	
	return 0;
}

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

int main(void)
{
	int n;

	while(cin >> n, n){
		int a,b,c;

		while(--n, n >= 0){
			cin >> a >> b >> c;
			if(a == 100 || b == 100 || c == 100)
				cout << "A" << endl;

			else if((a+b)/2 >= 90)
				cout << "A" << endl;

			else if((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;
		}
	}

	return 0;
}