#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

LL extract_base(LL v, const vector<LL>& base) {
  for (LL b : base) {
    v = min(v, v^b);
  }
  return v;
}

int solve() {
  int N; cin >> N;
  vector<LL> A(N); cin >> A;
  string S; cin >> S;

  vector<LL> base;
  for (int i = N - 1; i >= 0; --i) {
    LL a = A[i];
    if (S[i] == '0') {
      a = extract_base(a, base);
      if (a != 0) base.push_back(a);
    } else {
      a = extract_base(a, base);
      if (a != 0) return 1;
    }
  }
  return 0;
}

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; ++i) {
    cout << solve() << endl;;
  }
}
