#include <stdbool.h>
#include <stdio.h>
typedef long long ll;
int main() {
	int test;
	scanf("%d", &test);
	while (test--) {
		ll x = 0;
		int n;
		int bita[200][33] = {0};
		char s[201];
		scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			ll a;
			scanf("%lld", &a);
			for (int j = 0; j <= 32; j++) {
				if ((a >> j) & 1) {
					bita[i][j] = 1;
				}
			}
		}
		scanf("%s", s);
		bool is0 = true;
		for (int i = 0; i <= 32; i++) {
			for (int j = n - 1; j >= 0; j--) {
				if (bita[j][i]) {
					if (s[j] == '1') {
						is0 = false;
					}
					break;
				}
			}
		}

		if (is0) {
			printf("0\n");
		} else {
			printf("1\n");
		}
	}
	return 0;
}
