#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    vector<long long> b;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      long long cur = a[i];
      for (auto& x : b) {
        cur = min(cur, cur ^ x);
      }
      if (cur > 0) {
        if (s[i] == '1') {
          ans = 1;
          break;
        } else {
          b.push_back(cur);
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200 + 10;
ll a[maxn];

const int L = 63;
ll d[L];
bool add(ll x){
    for(int i = L - 1; i >= 0; i--) if(x & 1ll << i){
        if(d[i] == -1){d[i] = x; return true;}
        x ^= d[i];
    }
    return false;
}

int main(){
//    Fast;
    int t; scanf("%d", &t); while(t--){
        memset(d, -1, sizeof d);

        int n; scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%lld", a + i);
        char s[maxn]; scanf("%s", s);
        int flag = 0;
        for(int i = n - 1; i >= 0; i--){
            if(add(a[i]) && s[i] == '1'){
                flag = 1;
                break;
            }
        }
        printf("%d\n", flag);
    }
    return 0;
}

