#include <cstdio>
#include <cstring>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std; 
typedef long long ll;
const int maxN=200+5;
int T;
int N;
ll A[maxN];
ll base[64];
char S[maxN];
void ins(ll x) {
	for(int i=62;~i;--i) if(x>>i&1) {
		if(base[i]) x^=base[i];
		else {
			for(int j=i+1;j<63;++j) if(base[j]>>i&1) {
				base[j]^=x;
			}
			for(int j=i-1;~j;--j) if(x>>j&1) {
				x^=base[j];
			}
			base[i]=x;
			break;
		}
	}
}
bool sol() {
	memset(base,0,sizeof(base));
	for(int i=N;i>=1;--i) {
		if(S[i]=='0') {
			ins(A[i]);
		}
		else {
			for(int j=62;~j;--j) if(A[i]>>j&1) {
				if(!base[j]) return 1;
				A[i]^=base[j];
			}
		}
	}
	return 0;
}
int main() {
	scanf("%d",&T);
	for(int kase=1;kase<=T;++kase) {
		scanf("%d",&N);
		for(int i=1;i<=N;++i) scanf("%lld",&A[i]);
		scanf("%s",S+1);
		printf("%d\n",sol());
	}
	return 0;
}
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
    ll n;cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[n-i-1];
    }
    string s;cin>>s;
    set<ll,greater<ll>>basis;
    reverse(s.begin(),s.end());
    for(int i=0;i<n;i++){
        for(auto j:basis){
            arr[i]=min(arr[i],arr[i]^j);
        }
        if(arr[i]==0){
            continue;
        }
        if( s[i]=='0' )
            basis.insert(arr[i]);
        if( s[i]=='1' ){
            cout<<1<<"\n";
            return;
        }
    }
    cout<<0<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}



