#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;
}
#include<bits/stdc++.h>
using namespace std;
int main(){

  int n;
  string str;
  cin >> n;
  
  for(int i=0;i<n;i++){
    
    int out = 0;
    int a[4] = {};
    
    while(out != 3){
      
      cin >> str;
      
      if(str == "OUT") out++;
      else if(str == "HOMERUN"){
	a[3] += a[0]+a[1]+a[2]+1;
	a[0] = a[1] = a[2] = 0;
      }
      else if(str == "HIT"){
	a[3] += a[2];
	a[2] = 0;
	a[2] = a[1];
	a[1] = 0;
	a[1] = a[0];
	a[0] = 1;
      }
      
    }
    cout << a[3] << endl;
  }
  return (0);
}