#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 200
#define LN 63
#define ull unsigned long long
using namespace std;
int n,ans;ull a[N+5],v[LN+5];char op[N+5];
I void Clear() {ans=0;for(RI i=LN;~i;--i) v[i]=0;}
I void Ins(ull x)
{
	for(RI i=LN;~i;--i) if((x>>i)&1) {if(!v[i]) return (void)(v[i]=x);x^=v[i];}
}
I bool Q(ull x)
{
	for(RI i=LN;~i;--i) if((x>>i)&1) {if(!v[i]) return 0;x^=v[i];}return 1;
}
int main()
{
	RI Tt,i;scanf("%d",&Tt);W(Tt--)
	{
		for(Clear(),scanf("%d",&n),i=1;i<=n;++i) scanf("%llu",a+i);scanf("%s",op+1);
		for(ans=1,i=n;i;--i) if(a[i])
			{if(op[i]=='1'&&!Q(a[i])) {ans=0;break;}op[i]=='0'&&(Ins(a[i]),0);}
		putchar(49-ans),putchar('\n');
	}return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

void solve() {
    int N;
    cin >> N;
    vector<lint> A(N);
    rep(i, N) cin >> A[i];
    string S;
    cin >> S;
    
    vector<lint> base;
    for (int i = N - 1; i >= 0; --i) {
        lint x = A[i];
        for (auto b : base) {
            x = min(x, x ^ b);
        }
        if (x) {
            if (S[i] == '0') {
                base.push_back(x);
                sort(base.rbegin(), base.rend());
            } else {
                cout << 1 << "\n";
                return;
            }
        }
    }
    cout << 0 << "\n";
}

int main() {
    int T;
    cin >> T;
    rep(i, T) solve();
    return 0;
}
