#include <bits/stdc++.h>
using namespace std;

int main(){
    int T;
    cin >> T;
    for (int t = 0; t < T; t++){
        [](){
        int n;
        cin >> n;
        vector<uint64_t> A(n);
        copy_n(istream_iterator<uint64_t>(cin), n, A.begin());
        string S;
        cin >> S;

        vector<uint64_t> base;
        for (int i = n - 1; i >= 0; i--){
            auto a = A[i];
            for (const auto &b: base)
                a = min(a, a ^ b);
            if (a != 0)
                base.push_back(a);
            if (a != 0 and S[i] == '1'){
                puts("1");
                return;
            }
        }
        puts("0");
        }();
    }
}