#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {
public:
	UL N;
	ULL A[200];
	string S;

	void Solve() {
		UL T; scanf("%u", &T);
		while (T--) {
			scanf("%u", &N);
			rep(i, N) scanf("%llu", &A[i]);
			cin >> S;
			reverse(S.begin(), S.end());
			reverse(A, A + N);
			UL ans = 0;
			rep(i, N) {
				if (S[i] == '0') {
					ULL d = ~(A[i] - 1) & A[i];
					for (UL j = i + 1; j < N; j++)
						if (A[j] & d) A[j] ^= A[i];
				}
				else {
					if (A[i]) {
						ans = 1;
					}
				}
			}
			printf("%u\n", ans);
		}
	}
};

int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
