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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
bool HasBit(ll x, int b) {
    return (x >> b) & 1;
}

class XorSet {
public:
    static constexpr int kMaxBit = 60;

    XorSet() : basis(kMaxBit, 0) {
    }

    void Insert(ll val) {
        for (int b = 0; b < kMaxBit; ++b) {
            if (HasBit(val, b)) {
                if (basis[b] == 0) {
                    basis[b] = val;
                    ++size;
                    return;
                }
                val ^= basis[b];
            }
        }
    }

    int Size() const { return size; }

    bool Contains(ll val) {
        for (int b = 0; b < kMaxBit; ++b) {
            if (HasBit(val, b)) {
                if (basis[b] == 0) {
                    return false;
                }
                val ^= basis[b];
            }
        }
        return true;
    }

    void Cross(ll val) {
        if (size == 0) {
            return;
        }
        if (has_0) {
            Insert(val);
        }
        for (ll b : basis) {
            Insert(b ^ val);
        }
    }

    void AddZero() {
        has_0 = true;
        ++size;
    }

private:
    vector<ll> basis;
    int size = 0;
    bool has_0 = false;
};

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int test_cases;
    cin >> test_cases;
    while (test_cases--) {
        int n;
        cin >> n;
        vector<ll> arr(n);
        loop(n) {
            cin >> arr[i];
        }
        string s;
        cin >> s;
        if (s.back() == '1') {
            cout << 1 << endl;
            continue;
        }
        vector<XorSet> dp(n + 1);
        dp[n].AddZero();
        for (int i = n - 1; i >= 0; --i) {
            if (s[i] == '0') {
                dp[i] = dp[i + 1];
                dp[i].Cross(arr[i]);
            } else {
                if (dp[i + 1].Contains(arr[i])) {
                    dp[i] = dp[i + 1];
                }
            }
        }
        cout << !dp[0].Size() << endl;
    }

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 3728