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 <stdio.h>

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

int main(void)
{
    int number;
    int pm, pe, pj;
    while (1) {
      scanf("%d", &number);// number of students to grade                                                                                                                            
      if (number == 0) {
        break;
      } else {
        for (int j = 0; j < number; j++) {
          int grade;
          scanf("%d %d %d", &pm, &pe, &pj);
          grade = grading(pm, pe, pj);
          if (grade == 1) {// grade 1 means class A                                                                                                                                  
            printf("A\n");
          } else if (grade == 2) {//grade 2 means class B                                                                                                                            
            printf("B\n");
          } else if (grade == 3) {//grade 3 means class C                                                                                                                            
            printf("C\n");
          }
        }
      }
    }
    return 0;
}

int grading(int pm, int pe, int pj)
{
    int grade;
    if ((pm == 100 || pe == 100 || pj == 100)) {
      grade = 1;
    } else if ((pm + pe) / 2 >= 90) {
      grade = 1;
    } else if ((pm + pe + pj) / 3 >= 80) {
      grade = 1;
    } else if ((pm + pe + pj) / 3 >= 70) {
      grade = 2;
    } else if ((pm + pe + pj) / 3 >= 50 && (pm >=80 || pe >=80)) {
      grade = 2;
    } else {
      grade = 3;
    }
    return grade;
}

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

C++: #include <cstdio>

int n;

int main(){
	while(scanf("%d", &n),n){
		for(int i = 0; i < n; i++){
			int pm, pe, pj,ave;
			scanf("%d%d%d", &pm, &pe, &pj);
			ave = (pm+pe+pj)/3;
			if(pm == 100 || pe == 100 || pj == 100 || ave >= 80 || (pm+pe)/2 >= 90) printf("A\n");
			else if(ave >= 70 || (ave>=50&&(pm>=80||pe>=80))) printf("B\n");
			else printf("C\n");
		}
	}
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

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;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int n;

  while(1) {
    cin >> n;
    if(!n) break;

    REP(i, n) {
      int pm, pe, pj;
      cin >> pm >> pe >> pj;
      if(pm == 100 || pe == 100 || pj == 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) && (pm >= 80 || pe >= 80)) cout << 'B' << endl;
      else cout << 'C' << endl; 
    }
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
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;
            if (max(pm, max(pe, pj)) == 100) {
                cout << "A" << endl;
            } else if (180 <= pm + pe) {
                cout << "A" << endl;
            } else if (240 <= pm + pe + pj) {
                cout << "A" << endl;
            } else if (210 <= pm + pe + pj) {
                cout << "B" << endl;
            } else if (150 <= pm + pe + pj && 80 <= max(pm, pe)) {
                cout << "B" << endl;
            } else {
                cout << "C" << endl;
            }
        }
    }
    return 0;
}

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


string solve(){
  vector<int> a;
  for(int i=0;i<3;i++){
    int tmp;
    cin>>tmp;
    a.push_back(tmp);
  }

  for(int i=0;i<a.size();i++){
    if(a[i]==100)return "A";
  }
  if(a[0]+a[1]>=90*2)return "A";
  int ave = (a[0]+a[1]+a[2])/3;
  if(ave>=80)return "A";
  if(ave>=70)return "B";
  if(ave>=50)if(a[0]>=80||a[1]>=80)return "B";
  return "C";
}


int main(){
  int n;
  while(cin>>n,n!=0){
    for(int i=0;i<n;i++){
      cout<<solve()<<endl;
    }
  }
}

C++: #include<stdio.h>
int main(void)
{
	int n,i,a[101],b[101],c[101],s,ss,sss;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[n],&b[n],&c[n]);
		ss=a[n]+b[n]+c[n];
		s=ss/3;
		sss=(a[n]+b[n])/2;
		if(100>=a[n] || 100>=b[n] || 100>=c[n]){
			printf("A\n");
		}
		else if(90>=sss){
			printf("A\n");
		}
		else if(s>=80){
			printf("A\n");
		}
		else if(s>=70){
			printf("B\n");
		}
		else if(s>=50 && b[n]>=80 || c[n]>=80){
			printf("B\n");
		}
		else{
			printf("C\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#define EPS 1e-10

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) >= 180)cout << "A" << endl;
      else if((A+B+C) >= 240)cout << "A" << endl;
      else if(A+B+C >= 210)cout << "B" << endl;
      else if((A+B+C)>=150 && (A>=80 || B>=80))cout << "B" << endl;
      else cout << "C" << endl;
    }
  }
  return 0;
}