#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int matrix_rank(vector<unsigned long long> A){
	int n=A.size(),r=0;
	rep(i,64){
		int piv=-1;
		for(int j=r;j<n;j++) if(A[j]>>i&1) {
			piv=j;
			break;
		}
		if(piv==-1) continue;

		for(int j=r;j<n;j++) if(j!=piv && A[j]>>i&1) {
			A[j]^=A[piv];
		}
		swap(A[r],A[piv]);
		r++;
	}
	return r;
}

void solve(){
	int n; cin>>n;
	vector<unsigned long long> a(n);
	rep(i,n) cin>>a[i];
	string s; cin>>s;

	vector<unsigned long long> A;
	int r=0;
	for(int i=n-1;i>=0;i--){
		A.emplace_back(a[i]);
		int r2=matrix_rank(A);
		if(r<r2 && s[i]=='1'){
			puts("1");
			return;
		}
		r=r2;
	}
	puts("0");
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second	

#define sz(a) ((int)(a.size()))
using namespace std;
const int mod = 998244353;
int mult(int a, int b)
{
	return a * (ll) b % mod;
}
int add(int a, int b)
{
	return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a,  int b)
{
	return a - b < 0 ? a - b + mod : a - b;
}
void Add(int &a, int b)
{
	a = add(a , b);
}
vector<ll> b;
void add(ll x)
{
	for(int i = 0; i < b.size(); i++)
	{
		ll t= b[i];
		if((x ^ t) < x)
		{
			x ^= t;
		}
	}
	if(x == 0)
		return;
	for(int i = 0; i < b.size(); i++)
	{

		if((x ^ b[i]) < b[i])
			b[i] ^= x;
	}
	b.pb(x);
	sort(b.begin() , b.end() , greater<ll>());
}
ll check(ll x)
{
	for(int i = 0; i < b.size(); i++)
	{
		ll t = b[i];
		if((x ^ t) < x)
		{
			x ^= t;
		}
	}
	return x;
}
int main() 
{
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		b.clear();
		vector<ll> a(n);
		for(auto & x : a)
			cin >> x;
		string s;
		cin >> s;
		reverse(a.begin() , a.end());
		reverse(s.begin() , s.end());
		bool pzdc = false;
		for(int i = 0; i < n; i++)
			if(s[i] == '0')
			{
				add(a[i]);
			}
			else 
			{
				pzdc |= check(a[i]) != 0;
			}
		cout << pzdc << endl;
	}
	
}










