#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define all(v) (v).begin(),v.end()
#define np next_permutation
using namespace std;
using vi=vector<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,j,n) for(int i=j;i<=n;i++)
#define vii vector<vi>
#define vb vector<bool>
#define pr pair<int,int>
#define vl vector<ll>
#define eb emplace_back
#define umap unordered_map<ll,int>
const int N=(int)1e5+11;

int n,t;
string s;

void solve(){
   cin>>n;
   vl a(n);
   for(int i=0;i<n;i++)
       cin>>a[i];
   cin>>s;
   vl b;
   for(int i=n-1;i>=0;i--){
      ll v=a[i];
      for(auto x:b){
        if(v > (v^x))
           v=v^x;
      }
      if(v){
           if(s[i]=='1'){
             cout<<1<<"\n";
             return;
           }
           b.pb(v);
      }
   }
   cout<<0<<"\n";
}
int main(){ 
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin>>t;
   while(t--) solve();
   return 0;
}

#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 210;
int n;
ll a[N];
char s[N];

ll b[N];
inline void init(){
	For(i,0,63) b[i]=0;
}
inline bool insert(ll x){
	Dow(i,63,0) if (x&(1ll<<i)){
		if (!b[i]) return b[i]=x,1;
			else x^=b[i];
	}
	return 0;
}

inline void solve(){
	n=read();
	For(i,1,n) a[i]=read();
	scanf("%s",s+1);
	init();
	Dow(i,n,1) if (s[i]=='0'){
		insert(a[i]);
	} else if (insert(a[i])) return puts("1"),void(0);
	puts("0");
}

int main(){
	int T=read();
	while (T--) solve();
}