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 <stdio.h>
#include <string.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
#include <ctime>
#include <bitset>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 1000000007
#define N 500005

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;}
template<typename U> U gcd(U a, U b){
    if(a == 0)return b;
    if(b == 0)return a;
    if(a >= b)return gcd(a % b, b);
    else return gcd(a, b % a);
}
int pow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return ans;
}
int pow(int a, ll b, int c){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % c;
        a = 1LL * a * a % c;
        b >>= 1;
    }
    return ans;
}

unordered_map<ll, int> dp[202];
ll b[202], a[202];
char s[202];
int solve(int x, int n, ll v, ll a[]){
  if(dp[x].count(v))return dp[x][v];
  if(x == n-1){
    if(v == 0 || v == a[x])return dp[x][v] = 0;
    return dp[x][v] = 1;
  }
  if(s[x] == '1'){
    int p = solve(x+1, n, v, a);
    if(p) return dp[x][v] = 1;
    int q = solve(x+1, n, v ^ a[x], a);
    if(q)return dp[x][v] = 1;
    return dp[x][v] = 0;
  }
  else{
    int p = solve(x+1, n, v, a);
    if(p == 0)return dp[x][v] = 0;
    int q = solve(x+1, n, v ^ a[x], a);
    if(q == 0)return dp[x][v] = 0;
    return dp[x][v] = 1;
  }
}
int main() {
  int ca = 0, T, i, j, k, m, n;
  scanf("%d", &T);
  while(T--){
    scanf("%d", &n);
    rep(i, 0, n)scanf("%lld", &b[i]);
    scanf("%s", s);
    if(s[n-1] == '1'){
      puts("1");
      continue;
    }
    int ans = 0;
    rep(i, 0, 60){
      rep(j, 0, n)dp[j].clear();
      rep(j, 0, n)a[j] = b[j] >> i & 1;
      if(solve(0, n, 0, a)){
        ans = 1;
        break;
      }
    }
    if(ans == 0){
      rep(j, 0, n)dp[j].clear();
      if(solve(0, n, 0, b)){
        ans = 1;
      }
    }
    puts(ans ? "1" : "0");
  }
}