#include <bits/stdc++.h>

using namespace std;

const int MX = 200, MB = 60;

long long a[MX], base[MB];
char s[MX + 1];

int main() {
	int T;
	ignore = scanf("%d", &T);
	while (T--) {
		int n;
		ignore = scanf("%d", &n);
		for (int i = 0; i < n; i++) ignore = scanf("%lld", a + i);
		ignore = scanf("%s", s);
		
		fill(base, base + MB, 0);
		
		int ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			bool added = false;
			long long val = a[i];
			for (int j = 0; j < MB; j++) {
				if (((val >> j) & 1) == 0) continue;
				
				if (base[j] == 0) {
					base[j] = val;
					added = true;
					break;
				}
				
				val ^= base[j];
			}
			
			if (s[i] == '1' && added) {
				ans = 1;
			}
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}
