#include <bits/stdc++.h>
using namespace std;
int t;
int n;
long long a[6001], b[6001], c[6001];
string s;
void add(long long mask) {
  for (int i = 61; i >= 0; i--) {
    if ((mask & ((long long)(1) << i))) {
      if (!c[i]) {
        c[i] = mask;
        for (int j = i - 1; j >= 0; j--)
          if (c[i] & ((long long)(1) << j)) c[i] ^= c[j];
        for (int j = i + 1; j <= 61; j++)
          if (c[j] & ((long long)(1) << i)) c[j] ^= c[i];
        return;
      }
      mask ^= c[i];
    }
  }
}
bool verify(long long u) {
  for (int i = 61; i >= 0; i--)
    if (u & ((long long)1 << i)) u ^= c[i];
  return (u == 0);
}
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  cin >> s;
  for (int i = 1; i <= n; i++) b[i] = (s[i - 1] == '0' ? 0 : 1);
  for (int i = 0; i <= 99; i++) c[i] = 0;
  for (int i = n; i >= 1; i--) {
    if (b[i] == 1) {
      if (!verify(a[i])) {
        printf("1\n");
        return;
      }
    } else {
      add(a[i]);
    }
  }
  printf("0\n");
}
int main() {
  scanf("%d", &t);
  while (t--) solve();
}
