#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        lint n;
        cin >> n;
        vector<lint> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        string s;
        cin >> s;
        lint ns = s.size();
        if (s[ns - 1] == '1') {
            cout << 1 << "\n";
            continue;
        }
        vector<lint> as;
        vector<lint> bs;
        lint prev = 0;
        int ret   = 0;
        for (int i = n - 1; i >= 0; --i) {
            if (s[i] == '1') {
                as.push_back(a[i]);
                prev = 1;
            } else {
                if (prev == 1) {
                    // hakidashi
                    vector<bool> used(bs.size(), false);
                    for (lint i = 62; i >= 0; --i) {
                        lint idx = -1;
                        for (int j = 0; j < (int)bs.size(); ++j) {
                            if (!used[j] && ((bs[j] >> i) & 1)) {
                                idx     = j;
                                used[j] = true;
                                break;
                            }
                        }
                        if (idx != -1) {
                            for (int j = 0; j < (int)bs.size(); ++j) {
                                if (((bs[j] >> i) & 1) && j != idx) {
                                    bs[j] ^= bs[idx];
                                }
                            }
                            for (int j = 0; j < (int)as.size(); ++j) {
                                if (as[j] >> i & 1) {
                                    as[j] ^= bs[idx];
                                }
                            }
                        }
                    }
                    for (auto &x : as) {
                        if (x != 0) {
                            ret = 1;
                            break;
                        }
                    }
                    as.clear();
                }
                bs.push_back(a[i]);
                prev = 0;
            }
            if (ret == 1)
                break;
        }
        if (prev == 1) {
            vector<bool> used(bs.size(), false);
            for (lint i = 62; i >= 0; --i) {
                int idx = -1;
                for (int j = 0; j < (int)bs.size(); ++j) {
                    if (!used[j] && (bs[j] >> i & 1)) {
                        idx     = j;
                        used[j] = true;
                        break;
                    }
                }
                if (idx != -1) {
                    for (int j = 0; j < (int)bs.size(); ++j) {
                        if ((bs[j] >> i & 1) && j != idx) {
                            bs[j] ^= bs[idx];
                        }
                    }
                    for (int j = 0; j < (int)as.size(); ++j) {
                        if (as[j] >> i & 1) {
                            as[j] ^= bs[idx];
                        }
                    }
                }
            }
            // hakidashi
        }
        for (auto &x : as) {
            if (x != 0) {
                ret = 1;
                break;
            }
        }
        cout << ret << "\n";
    }
    return 0;
}

Measured memory_bytes: 3620