#include <iostream>
using namespace std;

int main(){
    int n;
    while( cin >> n, n ){
        int pm, pe, pj;
        while( n-- > 0 ){
            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;
}
#include <bits/stdc++.h>
using namespace std;

const int N = 5e3 + 11;
int a[N];

int main() {
	ios :: sync_with_stdio(false);
	int n;
	while(cin >> n) {
		if(n == 0) break;
		for(int i = 0; i < n; i ++)
			cin >> a[i];
		int ans = a[0], pre = min(a[0], 0);
		for(int i = 1; i < n; i ++) {
			a[i] += a[i - 1];
			ans = max(ans, a[i] - pre);
			pre = min(pre, a[i]);
		}
		cout << ans << '\n';
	}
	return 0;
}