Problem:
Score : 400 points

Problem Statement

There are two persons, numbered 0 and 1, and a variable x whose initial value is 0.
The two persons now play a game.
The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):

Person S_i does one of the following:

Replace x with x \oplus A_i, where \oplus represents bitwise XOR.

Do nothing.

Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.

Determine whether x becomes 0 at the end of the game when the two persons play optimally.

Solve T test cases for each input file.

Constraints

1 \leq T \leq 100

1 \leq N \leq 200

1 \leq A_i \leq 10^{18}

S is a string of length N consisting of 0 and 1.

All numbers in input are integers.

Input

Input is given from Standard Input in the following format.
The first line is as follows:

T

Then, T test cases follow.
Each test case is given in the following format:

N
A_1 A_2 \cdots A_N
S

Output

For each test case, print a line containing 0 if x becomes 0 at the end of the game, and 1 otherwise.

Sample Input 1

3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000

Sample Output 1

1
0
0

In the first test case, if Person 1 replaces x with 0 \oplus 1=1, we surely have x \neq 0 at the end of the game, regardless of the choice of Person 0.

In the second test case, regardless of the choice of Person 1, Person 0 can make x=0 with a suitable choice.

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

void init(){
	
}

vector<LL> v4;

void create(){
	int i,j,k;
	LL a,b;
	for(i=0,k=0;i<60 && k<v4.size();i++){
		a=(LL)1<<i;
		for(j=k;j<v4.size();j++){
			if(v4[j]&a){
				swap(v4[j],v4[k]);
				break;
			}
		}
		if((v4[k]&a)==0)continue;
		for(j=k+1;j<v4.size();j++){
			if(v4[j]&a)v4[j]^=v4[k];
		}
		k++;
	}
}

bool solve(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	vector<LL> v1,v2,v3;
	string sa;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		v3.push_back(a);
	}
	cin>>sa;
	for(i=0;i<n;i++){
		if(sa[i]=='0')v1.push_back(v3[i]);
		else v2.push_back(v3[i]);
	}
	reverse(v1.begin(),v1.end());
	v4=v1;
	create();
	for(i=0;i<n;i++){
		if(sa[i]=='0'){
			v1.pop_back();
			v4=v1;
			create();
			continue;
		}
		for(j=0,k=0;j<v4.size();j++){
			if(v4[j]==0)continue;
			while((v4[j]&((LL)1<<k))==0 && k<60){
				if(v3[i]&((LL)1<<k))return false;
				k++;
			}
			if(k>=60)break;
			if(v3[i]&((LL)1<<k))v3[i]^=v4[j];
		}
		if(v3[i])return false;
	}
	return true;
}

int main(){
	int n,i;
	init();
	cin>>n;
	for(i=0;i<n;i++){
		if(solve())cout<<0<<endl;
		else cout<<1<<endl;
	}
}