#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

char school(int m, int e, int j)
{
if( m == 100 || e == 100 || j == 100 )
        return 'A';
    if( (m+e)>=180 || (m+e+j)>=240)
        return 'A';
    if( (m+e+j)>=210 || ( (m+e+j)>=150 && (m>=80||e>=80) ) )
		return 'B';
	else
    return 'C';
}
int main()
{
	int x, m, e, j;
	while(cin>>x)
	{
		for(int i=0; i<x; i++)
		{
			cin>>m>>e>>j;
			
		
		cout<<school(m,e,j)<<endl;
		}
	}
	
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    vector<long long> b;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      long long cur = a[i];
      for (auto& x : b) {
        cur = min(cur, cur ^ x);
      }
      if (cur > 0) {
        if (s[i] == '1') {
          ans = 1;
          break;
        } else {
          b.push_back(cur);
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
