#include <bits/stdc++.h>

using namespace std;

void solve() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (auto&& e : A) {
    cin >> e;
  }
  string S;
  cin >> S;
  vector<int64_t> B;
  for (int i = N - 1; i > -1; i--) {
    int64_t x = A[i];
    for (auto b : B) {
      x = min(x, x ^ b);
    }
    if (S[i] == '0') {
      if (x > 0) B.emplace_back(x);
    } else if (x > 0) {
      cout << 1 << '\n';
      return;
    }
  }
  cout << 0 << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    solve();
  }
  return 0;
}
