//Original Code:
//#include <iostream>
//#include <algorithm>
//#include <cmath>
//#include <stdio.h>
//#include <stdlib.h>
//#include <vector>
//#include <map>
//#include <queue>
//#include <set>
//#include <string>
//#include <string.h>
//#include <stack>
//#include <assert.h>
//#include <bitset>
//#include <self/vs>
//#define Endl endl
//#define mp make_pair
//#define ll long long 
//#define ull unsigned long long
//#define pii pair<int,int>
//#define pll pair<ll,ll>
//#define over(A) {cout<<A<<endl;exit(0);}
//#define all(A) A.begin(),A.end()
//#define ceil(a,b) ((a-1)/b+1)
//#define quickcin ios_base::sync_with_stdio(false);
//using namespace std;
//
//XorSpace <200> xs;
//void solve()
//{
//	int n;
//	string s;
//	ll a[205];
//	cin>>n;
//	for(int i=0;i<n;i++)
//	{
//		cin>>a[i];
//	}
//	cin>>s;
//	xs.clear();
//	for(int i=n-1;i>=0;i--)
//	{
//		if(s[i]=='0') xs.add(a[i]);
//		else
//		{
//			if(xs.query(a[i])) continue;
//			cout<<1<<endl;
//			return;
//		}
//	}
//	cout<<0<<endl;
//}
//
//int main()
//{
////	freopen("input.txt","r",stdin);
//	int T;
//	cin>>T;
//	while(T--)
//	{
//		solve();
//	}
//	return 0;
//}

//substituted with C++ Inliner
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#ifndef _SELF_VS
#define _SELF_VS 1
#ifndef _SELF_UTILITY
#define _SELF_UTILITY 1
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define quickcin ios_base::sync_with_stdio(false);
const int mod=1e9+7;
const int inf=1039074182;
const ll llinf=1LL*inf*inf;
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
template <typename T1,typename T2> inline void chadd(T1 &x,T2 b) {x+=b;if(x>=mod) x-=mod;}
template <typename T1,typename T2> inline void chmul(T1 &x,T2 b) {x=1LL*x*b%mod;}
template <typename T1,typename T2> inline void chmod(T1 &x,T2 b) {x%=b,x+=b;if(x>=b) x-=b;}
#endif

using namespace std;
template <size_t T>
bool operator < (bitset <T> a,bitset <T> b)
{
	for(int i=T-1;i>=0;i--)
	{
		if(a[i]!=b[i]) return a[i]<b[i];
	}
	return false;
}

template <int T>
struct XorSpace
{
	vector <bitset <T> > bases;
	vector <int> baseIDs;
	map <int,int> toXSID;
	vector <vector<int> > trace;
	int freeNum=0;
	int recordTrace=-1;
	void clear()
	{
		recordTrace=-1;
		freeNum=0;
		trace.clear();
		toXSID.clear();
		baseIDs.clear();
		bases.clear();
	}
	void error(string str)
	{
		cout<<str<<endl;
		exit(0);
	}
	void add(bitset <T> x)
	{
		if(recordTrace==1) error("You've ordered 'Record Trace' function, which is incompatible with single parameter function 'add'");
		recordTrace=0;
		for(auto &basis:bases)
		{
			chmin(x,x^basis);
		}
		if(x==0)
		{
			freeNum++;
			return;
		}
		else bases.push_back(x);
	}
	vector <int> expandTrace(vector <int> v)
	{
		vector <int> t;
		for(auto x:v)
		{
			for(auto u:trace[x])
			{
				t.push_back(u);
			}
		}
		vector <int> res;
		sort(all(t));
		for(int i=0,j=0;i<t.size();i=j)
		{
			for(j=i;j<t.size();j++)
			{
				if(t[i]!=t[j]) break;
			}
			if((j-i)&1) res.push_back(t[i]);
		}
		return res;
	}
	void add(bitset <T> x,int id)
	{
		vector <int> tmp;
		if(recordTrace==0) error("You've ordered 'Record Trace' function, which is incompatible with single parameter function 'add'");
		recordTrace=true;
		for(int i=0;i<bases.size();i++)
		{
			bitset <T> bit=bases[i]^x;
			if(bit<x)
			{
				x=bit;
				tmp.push_back(i);
			}
		}
		if(x==0)
		{
			freeNum++;
			return;
		}
		else
		{
			bases.push_back(x);
			toXSID[id]=baseIDs.size();
			baseIDs.push_back(id);
			vector <int> t;
			trace.push_back(expandTrace(tmp));
			trace.back().push_back((int)baseIDs.size()-1);
		}
	}
	bool query(bitset <T> x)
	{
		for(auto &basis:bases)
		{
			chmin(x,x^basis);
		}
		return (x==0);
	}
	bool query(bitset <T> x,bitset <T> key)
	{
		x&=key;
		for(auto &basis:bases)
		{
			chmin(x,x^(basis&key));
		}
		return (x==0);
	}
	pair<int,vector <int> > queryWithID(bitset <T> x)
	{
		bitset <T> tmp;
		vector <int> res;
		for(int i=0;i<bases.size();i++)
		{
			tmp=bases[i]^x;
			if(tmp<x)
			{
				x=tmp;
				res.push_back(baseIDs[i]);
			}
		}
		res=expandTrace(res);
		for(auto &x:res)
		{
			x=baseIDs[x];
		}
		return mp((x==0),res);
	}
	pair<int,vector <int> > queryWithID(bitset <T> x,bitset <T> key)
	{
		bitset <T> tmp;
		vector <int> res;
		x&=key;
		for(int i=0;i<bases.size();i++)
		{
			tmp=(bases[i]&key)^x;
			if(tmp<x)
			{
				x=tmp;
				res.push_back(i);
			}
		}
		res=expandTrace(res);
		for(auto &x:res)
		{
			x=baseIDs[x];
		}
		return mp((x==0),res);
	}
};
#endif
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define quickcin ios_base::sync_with_stdio(false);
using namespace std;

XorSpace <200> xs;
void solve()
{
	int n;
	string s;
	ll a[205];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	cin>>s;
	xs.clear();
	for(int i=n-1;i>=0;i--)
	{
		if(s[i]=='0') xs.add(a[i]);
		else
		{
			if(xs.query(a[i])) continue;
			cout<<1<<endl;
			return;
		}
	}
	cout<<0<<endl;
}

int main()
{
//	freopen("input.txt","r",stdin);
	int T;
	cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3584