#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const ll INF = 1e18+3;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;

#include <iostream>
#include <vector>
using namespace std;

void Gauss(vector<long long> &A) {
  int rank = 0;
  for (int d = 0; d < 60; ++d) {
    int pivot = -1;
    for (int i = rank; i < (int)A.size(); ++i) {
      if (A[i] & (1LL<<d)) {
        pivot = i;
        break;
      }
    }
    if (pivot == -1) continue;
    swap(A[rank], A[pivot]);
    for (int j = 0; j < (int)A.size(); ++j) {
      if (j == rank) continue;
      if (!(A[j] & (1LL<<d))) continue;
      A[j] ^= A[rank];
    }
    ++rank;
  }
}
int max_bit(long long bit){
    for (int i = 63; i >= 0; i--){
        if (bit & (1LL << i)){
            return i;
        }
    }
    return -1;
}
        
    
// BitMatrix
const int MAX_ROW = 610; // to be set
const int MAX_COL = 610; // to be set
struct BitMatrix {
    int n, m;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int n_ = 1, int m_ = 1) {n = n_; m = m_;}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
    inline friend ostream& operator << (ostream& s, BitMatrix M) {
        s << endl;
        for (int i = 0; i < M.n; ++i) {
            for (int j = 0; j < M.m; ++j) s << M.val[i][j];
            s << endl;
        }
        return s;
    }
};

inline BitMatrix operator * (BitMatrix A, BitMatrix B) {
    BitMatrix R(A.n, B.m);
    BitMatrix tB(B.m, B.n);
    for (int i = 0; i < tB.n; ++i) for (int j = 0; j < tB.m; ++j) tB[i][j] = B[j][i];
    for (int i = 0; i < R.n; ++i) for (int j = 0; j < R.m; ++j) R[i][j] = (A[i] & tB[j]).any();
    return R;
}

int linear_equation(BitMatrix A, vector<int> b) {
    int rank = 0;
    for (int i = 0; i < A.n; ++i) { A[i][A.m] = b[i]; }

    for (int i = 0; i < A.m; ++i) {
        int pivot = -1;
        for (int j = rank; j < A.n; ++j) {
            if (A[j][i]) {
                pivot = j;
                break;
            }
        }
        if (pivot != -1) {
            swap(A[pivot], A[rank]);
            for (int j = 0; j < A.n; ++j) if (j != rank && A[j][i]) A[j] ^= A[rank];
            ++rank;
        }
    }

    for (int i = rank; i < A.n; ++i) if (A[i][A.m]) return -1; // ���Ȃ�   
    return rank;
};
int main() {
    int T;
    cin >> T;
    rep(t, T){
        int N;
        string S;
        cin >> N;
        vector<long long> A(N), B;
        //vector<long long> B(N);
        rep(i, N)cin >> A[i];
        cin >> S;
        
        if (S[N - 1] == '1'){
            cout << 1 << endl;
            continue;
        }
        
        for (int n = N - 1; n >= 0; n--){
            if (S[n] == '0'){
                B.push_back(A[n]);
                Gauss(B);
            } else {
                
                
                BitMatrix AA(64, B.size());
                vector<int> bb(64);
                for (int d = 0; d < 64; ++d) {
                    for (int i = 0; i < N; ++i) {
                        if (B[i] & (1LL<<d)) AA[d][i] = 1;
                    }
                    if (A[n] & (1LL<<d)) bb[d] = 1;
                }
                int rank = linear_equation(AA, bb);
                
                if (rank == -1){
                    cout << 1 << endl;
                    goto end;
                }
#if 0
                long long res = A[n];
                //fprintf(stderr, "res = %Ld\n", res);
                sort(ALL(B));
                for (int i = B.size() - 1; i >= 0; i--){
                //rep(i, B.size()){
                    fprintf(stderr, "b[%d]: %d\n", i, B[i]);
                    if (max_bit(res) == max_bit(B[i])){
                    //if (res >= B[i]){
                        res ^= B[i];
                    }
                }
                if (res > 0){
                    cout << 1 << endl;
                    goto end;
                }
#endif
            }
        }
        cout << 0 << endl;
        end:
        ;
    }

}

Measured memory_bytes: 3692