#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void vout(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
    }
}

//from http://noshi91.hatenablog.com/entry/2019/03/31/174006
template <std::uint_fast64_t Modulus>
class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint operator^(const u64 rhs) const noexcept {
        return modint(*this) ^= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
    constexpr modint &operator^=(u64 exp) {
        modint rhs = modint(*this);
        a = 1;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
    friend ostream &operator<<(ostream &os, const modint &x) {
        os << x.a;
        return os;
    }
};
using mint = modint<MOD>;
const int maxH = 70, maxW = 300;
struct BitMatrix {
    bitset<maxW> a[maxH];
    int n, m;
    BitMatrix(int n, int m) : n(n), m(m) {}
    inline bitset<maxW> &operator[](int i) { return a[i]; }
};
//bitmatrix を掃き出し、rankを返す
int GaussJordan(BitMatrix &a, bool extended) {
    int rank = 0;
    for (int j = 0; j < a.m; j++) {
        if (extended && j + 1 == a.m) break;
        int piv = -1;
        for (int i = rank; i < a.n; i++) {
            if (a[i][j]) {
                piv = i;
                break;
            }
        }
        if (piv == -1) continue;
        swap(a[rank], a[piv]);
        piv = rank;
        for (int i = 0; i < a.n; i++) {
            if (i == piv) continue;
            if (a[i][j]) {
                a[i] ^= a[piv];
            }
        }
        rank++;
    }
    return rank;
}
//ax=b なるベクトルxを求め、自由度を返す O(HW^2) a:H*W b:H*1 x:W*1
int LinearEquation(BitMatrix a, vector<int> b, vector<int> &x) {
    BitMatrix na(a.n, a.m + 1);
    for (int i = 0; i < a.n; i++) {
        na[i] = a[i];
        na[i][a.m] = b[i];
    }
    int rank = GaussJordan(na, true);
    for (int i = rank; i < a.n; i++) {
        if (na[i][a.m]) return -1;
    }
    x.assign(a.m, 0);
    for (int i = 0; i < rank; i++) {
        x[i] = na[i][a.m];
    }
    return a.m - rank;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        V<ll> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];
        string s;
        cin >> s;
        bool f = true;
        if (s[n - 1] == '1') {
            cout << 1 << '\n';
            continue;
        }
        int c0 = 0, c1 = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '0') {
                if (c1 > 0) {
                    c0++;
                }
            } else {
                if (c0 > 0) {
                    int cnt = 0;
                    for (int j = i - c0; j < n; j++) {
                        if (s[j] == '0') cnt++;
                    }
                    BitMatrix m(61, cnt);
                    int id = 0;
                    for (int j = i - c0; j < n; j++) {
                        if (s[j] == '1') continue;
                        for (int k = 0; k < 61; k++) {
                            if ((a[j] >> k) & 1LL) {
                                m[k][id] = 1;
                            }
                        }
                        id++;
                    }
                    V<int> b(61), x;
                    for (int j = i - c1 - c0; j < i - c0; j++) {
                        for (int k = 0; k < 61; k++) {
                            if ((a[j] >> k) & 1LL) {
                                b[k] = 1;
                            } else {
                                b[k] = 0;
                            }
                        }
                        int res = LinearEquation(m, b, x);
                        if (res == -1) {
                            f = false;
                        }
                    }
                    c0 = 0, c1 = 1;
                } else {
                    c1++;
                }
            }
        }
        if (c0 > 0) {
            BitMatrix m(61, c0);
            for (int j = n - c0; j < n; j++) {
                for (int k = 0; k < 61; k++) {
                    if ((a[j] >> k) & 1LL) {
                        m[k][j - (n - c0)] = 1;
                    }
                }
            }
            V<int> b(61), x;
            for (int j = n - c1 - c0; j < n - c0; j++) {
                for (int k = 0; k < 61; k++) {
                    if ((a[j] >> k) & 1LL) {
                        b[k] = 1;
                    } else {
                        b[k] = 0;
                    }
                }
                int res = LinearEquation(m, b, x);
                if (res == -1) {
                    f = false;
                }
            }
        }
        cout << (f ? 0 : 1) << '\n';
    }
}


Measured memory_bytes: 3604