#include <stdio.h>
int N;
unsigned long long A[201];
unsigned int continuous = 0;

int process(unsigned long long a, int con) {

	if (a == 0) {
		return 2;
	}
	if (con >= continuous) {
		return 0;
	}

	unsigned long long ab = a ^ A[N - con-1];
	printf("-%llu/", ab);
	int n = con + 1;

	if (2 == process(ab, n)) {
		return 2;
	}

	if (2 == process(a, n)) {
		return 2;
	}

	return 0;
}

int main(void) {
	int T;

	//unsigned long long A[200];
	char S[201];
	unsigned long long x = 0;
	int result[200] = { 0 };

	scanf("%d", &T);

	for (int i = 0; i < T; i++) {
		scanf("%d", &N);

		for (int j = 0; j < N; j++) {
			scanf("%llu", &A[j]);
		}

		scanf("%s", S);

		if (S[N-1] == '0') {
			continuous = 1;
			for (int j = 1; S[N - 1 - j] == '0'; continuous++, j++) {

			}
		}
		else {
			continuous = 0;
		}

		for (int j = 0; j < N - continuous; j++) {
			if (S[j] == '0') {//target x=0
				if (x == 0) {

				}
				else {
					x = x ^ A[j];
				}
			}
			else {//target x=1
				if (x != 0) {

				}
				else {
					x = x ^ A[j];
				}
			}
				printf("x:%llu a:%llu s:%c\n", x,A[j],S[j]);
		}

		if (process(x, 0) == 2) {
			x = 0;
		}
		else {
			x = 1;
		}

		if (x == 0) {
			result[i] = 0;
		}
		else {
			result[i] = 1;
		}
		x = 0;
		continuous = 0;
	}

	for (int i = 0; i < T; i++) {
		printf("%d\n", result[i]);
	}

	return 0;
}