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>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

int n;

int main() {
  while(cin >> n, n) {
    rep(i, n) {
      int pm, pe, pj;
      cin >> pm >> pe >> pj;
      float tmp1 = (pm + pe) / 2.0;
      float tmp2 = (pm + pe + pj) / 3.0;
      if(tmp1 >= 90 || tmp2 >= 80 || pm == 100 || pe == 100 || pj == 100) {
        cout << 'A' << endl;
      } else if (tmp2 >= 70 || (tmp2 >= 50 && (pm >= 80 || pe >= 80))) {
        cout << 'B' << endl;
      } else {
        cout << 'C' << endl;
      }
    }
  }
  return 0;
}

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

char Division_class(int, int, int);

int main(void)
{
  int pm[10000], pe[10000], pj[10000];
  char s_class[10000];
  int n;
  
  while(1)
    {
      cin >> n;
      if(n == 0) break;
      
      for(int i = 0 ; i < n ; i++)
	{
	  cin >> pm[i] >> pe[i] >> pj[i];
	  s_class[i] = Division_class(pm[i], pe[i], pj[i]); 
	}
      for(int i = 0 ; i < n ; i++)
	{
	  cout << s_class[i] << endl;
	}
    }
  return 0;
}

char Division_class(int math, int english, int japanese)
{
  if(math == 100 || english == 100 || japanese == 100) return 'A';
  if(((math + english) / 2) >= 90) return 'A';
  if(((math + english + japanese) / 3) >= 80) return 'A';
  if(((math + english + japanese) / 3) >= 70) return 'B';
  if(((math + english + japanese) / 3) >= 50 && math >= 80 || english >= 80) return 'B';
  else return 'C';
}

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

int main(){
	int n;
	char s[10000];
	int pm, pe, pj;
	int sum;
	
	for(;;){
		for(int i = 0; i < 10000; i++) s[i] = 0;
		sum = 0;
		cin >> n;
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			cin >> pm >> pe >> pj;
			sum = pm + pe + pj;
			if(pm == 100 || pe == 100 || pj == 100) s[i] = 'A';
			else if((pm + pe) / 2 >= 90) s[i] = 'A';
			else if(sum / 3 >= 80) s[i] = 'A';
			else if(sum / 3 >= 70 && sum / 3 < 80) s[i] = 'B';
			else if(sum / 3 >= 50 && (pm >= 80 || pe >= 80)) s[i] = 'B';
			else s[i] = 'C';
		}
		for(int i = 0; i < n; i++){
			cout << s[i] << endl;
		}
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
    int n;
    while(cin >> n, n){
        for(int i = 0; i < n; i++){
            int m,e,j;
            cin >> m >> e >> j;
            int sum = m + e + j;
            if(m == 100 || e == 100 || j == 100)cout << "A" << endl;
            else if(m+e >= 90*2 || sum >= 80*3)cout << "A" << endl;
            else if(sum >= 70*3)cout << "B" << endl;
            else if(sum >= 50*3 && (m >= 80 || e >= 80))cout << "B" << endl;
            else cout << "C" << endl;
        }
    }
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[10001][4],d[10001],f,g,h,j,i,k;
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			for(j=0;j<3;j++) scanf("%d",&s[i][j]);
				if(s[i][0]==100||s[i][1]==100||s[i][2]==100) d[i]=1;
				else if((s[i][0]+s[i][1])/2>=90) d[i]=1;
				else if((s[i][0]+s[i][1]+s[i][2])/3>=80) d[i]=1;
				else if((s[i][0]+s[i][1]+s[i][2])/3>=70) d[i]=2;
				else if((s[i][0]+s[i][1]+s[i][2])/3>=50&&s[i][0]>=80||s[i][1]>=80) d[i]=2;
				else d[i]=3;
		}
		for(i=0;i<a;i++){
			if(d[i]==1) printf("A\n");
			if(d[i]==2) printf("B\n");
			if(d[i]==3) printf("C\n");
		}
	}
	return 0;
}

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

int main(){
    int n,pm,pe,pj;
    while(cin>>n,n){
        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;
    }
}

C++: /* 
 * File:   main.cpp
 * Author: freebsd
 *
 * Created on 2014/08/28, 10:07
 */

#include <cstdio>

using namespace std;

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

C++: #include<stdio.h>

void dividing(int pm, int pe, int pj);

int main(void)
{
  int n, pm, pe, pj;
  int i;
  while (1) {
  scanf("%d", &n);
  if (n == 0) {
    break;
  } else {
  while (i < n) {
    scanf("%d %d %d", &pm, &pe, &pj);
    dividing(pm, pe, pj);
    i++;
  }
  }
  }
  return 0;
}

void dividing(int pm, int pe, int pj)
{
  if (pm == 100 || pe == 100 || pj == 100) {
    printf("A\n");
  }
  else if ((pm + pe) / 2 > 90){
    printf("A\n");
  }
  else if ((pm + pe + pj) / 3 >80){
    printf("A\n");
  }
  else if ((pm + pe + pj) / 3 > 70){
    printf("B\n");
  }
  else if((pm + pe + pj) / 3 > 50 && (pm > 80 || pe > 80)){
    printf("B\n");
  } else {
    printf("C\n");
  }

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int pm,pe,pj,pa,cl;
  int i=0,l;
  char a[100000];
  cin>>cl;
  while(cl!=0){
    l=i;
    for(int j=0;j<cl;j++){
      cin>>pm>>pe>>pj;
      pa=(pm+pe+pj)/3;
      if(pm==100||pe==100||pj==100||90<=(pm+pe)/2||80<=pa)a[i]='A';
      else if(70<=pa||((80<=pe||80<=pm)&&50<=pa))a[i]='B';      
      else a[i]='C';
      i++;
    }
    for(int j=l;j<i;j++)
      cout<<a[j]<<endl;
    cin >> cl;
  }
  
  
  return 0;
}

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

int main(){
    int n,pm,pe,pj;
    while(cin>>n,n){
        while(n--){
            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;
        }
    }
}