#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N,T;
    string S;
    cin >> T;
    for(ll i=0;i<T;++i){
        cin >> N;
        vector<ll> A(N,0);
        for(ll i=0;i<N;++i)cin>>A[i];
        cin >> S;
        vector<ll> nl={0};
        bool ans=1;
        for(ll j=N-1;j>=0;--j){
            if(S[j]=='0'){
                ll x=A[j];
                for(auto p: nl)chmin(x,x^p);
                for(auto p: nl)chmin(p,x^p);
                if(x)nl.emplace_back(x);
            }
            else{
                ll x=A[j];
                for(auto p: nl)chmin(x,x^p);
                if(x){ans=0;break;}
            }
        }
        if(ans)prt(0)
        else prt(1)
    }
    return 0;
}

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=205,P=1e9+7,L=62;

int mul(int a,int b){ return 1ll*a*b%P; }
//int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int n,T;
ll a[N],pr[L+2],bk[L+2],ans;
char s[N];
void add(ll *b,ll x){
	dec(i,L,0){
		if((x>>i)&1){
			if(b[i])x^=b[i];
			else {b[i]=x; break; }
		}
	}
}
bool test(ll *b,ll x){
	dec(i,L,0)if((x>>i)&1){
		x^=b[i];
	}
	return x==0;
}
bool equal(ll *b1,ll *b2){
	dec(i,L,0)if(b1[i]){
		if(!test(b2,b1[i]))return false;
	}
	return true;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in","r",stdin); 
#endif
	read(T); 
	while(T--){
		read(n); 
		rep(i,1,n)read(a[i]); 
		scanf("%s",s+1); 
		ans=0;
		mem(bk,0);
		dec(i,n,1){
			if(s[i]=='0')add(bk,a[i]);
			else ans|=!test(bk,a[i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}
