#include <iostream>
using namespace std;

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    int pm[n], pe[n], pj[n];
    double average[n];
    double ave_me[n];
    for(int i = 0; i < n; i++) {
      cin >> pm[i] >> pe[i] >> pj[i];
      average[i] = (pm[i]+pe[i]+pj[i])/3.0;
      ave_me[i] = (pm[i]+pe[i])/2.0;
    }
    char grade[n];
    for(int i = 0; i < n; i++) {
      if(pm[i] == 100 || pe[i] == 100 || pj[i] == 100) {
	grade[i] = 'A';
      } else if(ave_me[i] >= 90) {
	grade[i] = 'A';
      } else if(average[i] >= 80) {
	grade[i] = 'A';
      } else if(average[i] >= 70) {
	grade[i] = 'B';
      } else if(average[i] >= 50 && (pm[i] >= 80 || pe[i] >= 80)) {
	grade[i] = 'B';
      } else {
	grade[i] = 'C';
      }
      cout << grade[i] << endl;
    }
  }
  return 0;
}
#include <iostream>
#include <vector>
using namespace std;

int main() {

  while( true ) {

    long long int a, b, c;
    cin >> a >> b >> c;
    if ( a == 0 ) break;

    vector< long long int > ans;
    for ( long long int i = 0; i < a + b + c; i++ ) {
      ans.push_back( 2 );
    }

    long long int n;
    cin >> n;

    vector< long long int > v_a, v_b, v_c;

    for ( long long int i = 0; i < n; i++ ) {

      long long int in_a, in_b, in_c, r;
      cin >> in_a >> in_b >> in_c >> r;

      if ( r == 1 ) {
	ans[ in_a - 1 ] = 1;
	ans[ in_b - 1 ] = 1;
	ans[ in_c - 1 ] = 1;
      }else {
	v_a.push_back( in_a );
	v_b.push_back( in_b );
	v_c.push_back( in_c );
      }

    }

    for ( long long int i = 0; i < v_a.size(); i++ ) {
      if ( ans[ v_a[i] - 1 ] == 1 && ans[ v_b[i] - 1 ] == 1 ) ans[ v_c[i] - 1 ] = 0;
      if ( ans[ v_a[i] - 1 ] == 1 && ans[ v_c[i] - 1 ] == 1 ) ans[ v_b[i] - 1 ] = 0;
      if ( ans[ v_b[i] - 1 ] == 1 && ans[ v_c[i] - 1 ] == 1 ) ans[ v_a[i] - 1 ] = 0;
    }

    for ( long long int i = 0; i < a + b + c; i++ ) {
      cout << ans[i] << endl;
    }

  }

  return 0;

}