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(cin>>n, n) {
    for(int i=0; i<n; ++i) {
      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;
    }
  }
}

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

int grading(int x, int y, int z, char rank)
{    
    int sum2 = x + y;
    int sum3 = x + y + z;
    if(x == 100 || y == 100 || z == 100){
        rank = 'A';
    }else if(sum2 >= 180){
        rank = 'A';
    }else if(sum3 >= 240){
        rank = 'A';        
    }else if(sum3 >= 210){
        rank = 'B';        
    }else if(sum3 >= 150 && (x >= 80 || y >= 80)){
        rank = 'B';        
    }else{
        rank = 'C'; 
    }       
}
    

int main(void)
{   
    int rep, ma, en, ja;
    char rank;
    while(true){
        scanf("%d", &rep);
        if(rep == 0){
            break;
        }
        for(int i = 0; i < rep; ++i){
            scanf ("%d%d%d", &ma, &en, &ja);
            grading(ma, en, ja,rank);
            printf("%c\n", rank);
        }
    }
    return 0;        
}

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

int main() {
	int n,c;
	double h,pm,pe,pj;
	while(cin >> n && n!=0) {
	for (;n>0;n--) {
		c=2;
		cin >> pm >> pe >> pj;
		h=(pm+pe+pj)/3;
		if ((h>=50 && (pm>=80 || pe>=80)) || h>=70) c=1;
		if (h>=80 || ((pm+pe)/2>=90) || pm==100 || pe==100 || pj==100) c=0;
		cout << (char)('A'+c) << endl;
	}
}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
	int n;
	while(cin >> n,n){
		rep(i,n){
			int pm,pe,pj;
			cin >> pm >> pe >> pj;
			int cmax=max({pm,pe,pj}),sum=pm+pe+pj;
			char ans='C';
			if(sum>=150&&(pm>=80||pe>=80)) ans='B';
			if(sum>=210) ans='B';
			if(sum>=240) ans='A';
			if(pm+pe>=180) ans='A';
			if(cmax==100) ans='A';
			printf("%c\n",ans);
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,pj,pm,pe;
	while(1){
		cin>>n
		if(n==0) break;
		for(int i=1;i<=n;i++){
			cin>>pm>>pe>>pj;
			if(pm==100||pe==100||pm==100){
				cout<<"A"<<endl;

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

C++: #include <stdio.h>

void divide(int math, int english, int japanese);

int main(void)
{
    int dataset;
    int math, english, japanese;

    while (1){
        scanf("%d", &dataset);
        if (dataset == 0){
            break;
        } else {
            while (dataset--){
                scanf("%d %d %d", &math, &english, &japanese);
                divide(math, english, japanese);
            }
        }
    }

    return 0;
}

void divide(int math, int english, int japanese)
{
    int sum = math + english + japanese;

    if (math == 100 || english == 100 || japanese == 100){
        printf("A\n");
    } else if (math + english >= 90 * 2){
        printf("A\n");
    } else if (sum >= 80 * 3){
        printf("A\n");
    } else if (sum >= 70 * 3){
        printf("B\n");
    } else if (sum >= 50 * 3 && (math >= 80 || english >= 80)){
        printf("B\n");
    } else {
        printf("C\n");
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{
		int m, e, j, p;
		rep(i, n)
		{
			cin >> m >> e >> j;

			p = m + e + j;

			if((m == 100 || e == 100 || j == 100) || (90 <= (m + e) / 2) || (80 <= p / 3))
				cout << "A" << endl;
			else if(70 <= p / 3 || (50 <= p / 3 && (80 <= m || 80 <= e)))
				cout << "B" << endl;
			else
				cout << "C" << endl;
		}
	}
}

C++: #include <bits/stdc++.h>

#define rep_(v, f, l) for (int v = (f); v < (l); ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
    int n;
    while (n = in()){
        rep(i, n){
            int pm, pe, pj;
            pm = in();
            pe = in();
            pj = in();
            int all_ave = (pm + pe + pj) / 3.;
            int me_ave = (pm + pe) / 2.;
            int is_perfect = pm == 100 || pe == 100 || pj == 100;
            if (is_perfect || me_ave >= 90 || all_ave >= 80 || (all_ave >= 70 && max(pm, pe) >= 80)){
                puts("A");
            }
            else if (all_ave >= 70 || (all_ave >= 50 && max(pm, pe) >= 80)){
                puts("B");
            }
            else {
                puts("C");
            }
        }
    }

    return (0);
}