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: Time Limit Exceeded)

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pair<int,int>> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(a) scanf("%d", &a)
#define rii(a,b) scanf("%d %d", &a, &b)
#define riii(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define rl(a) scanf("%lld", &a)
#define rll(a,b) scanf("%lld %lld", &a, &b)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second

const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int maxN = 1e5; // CAMBIAR ESTE

// GJNM
int n;
ll A[300], SUF[300];
char S[300];
map < pair< int, ll > , bool > dp;

bool f(int ind, ll acum){
	if ( ind == n && acum == 0 )
		return true;
	if ( ind == n )
		return false;
	if ( dp.find({ind, acum}) != dp.end() )
		return dp[{ind,acum}];

	if ( S[ind] == '0' ){ // want to make x == 0
		if ( acum & (~SUF[ind]) )
			return dp[{ind, acum}] = false;

		dp[{ind, acum}] = f(ind+1, acum) || f(ind+1, acum^A[ind]);
	}
	else{ // want to make x != 0
		if ( acum & (~SUF[ind+1]) )
			return dp[{ind, acum}] = false;
		
		dp[{ind, acum}] = f(ind+1, acum) && f(ind+1, acum^A[ind]);
	}
	return dp[{ind, acum}];
}


int main(){
	int t;
	ri(t);
	while(t--){
		ri(n);
		FOR(i,0,n)
			rl(A[i]);
		scanf("%s", S);
		ll play_0 = 0, play_1 = 0;
		SUF[n] = 0;
		ROF(i, n-1, -1){
			if ( S[i] == '0' )
				SUF[i] = SUF[i+1] | A[i];
			else
				SUF[i] = SUF[i+1]; 
		}

		dp.clear();
		bool ans = f(0, 0);
		if ( ans )
			printf("0\n");
		else
			printf("1\n");
	}
	return 0;
}