#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

#include <cmath>
#include <queue>
#include <stack>
#include <random>
#include <ctime>
#include <cmath>

using namespace std;

#define LL long long

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x = 0) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

std::default_random_engine randomEngine;
std::uniform_real_distribution<double> RandomDoubleGen(0.0, 1.0);

void initialize_random() {
	randomEngine = std::default_random_engine((unsigned)time(NULL));
}
double randomDouble() {
	return RandomDoubleGen(randomEngine);
}

LL Mint::md = 1000000007;
string s;
int n;
vector<LL> a;
vector<LL> sp;
vector<vector<int> > spb;

int getBitN(LL x) {
	int res = 0;
	while (x) {
		res += (int)(x % 2);
		x = x >> 1;
	}
	return res;
}

const int maxTimeN = 50;
int maxBit = 64;

vector<int> toBitSet(LL x) {
	vector<int> res;
	while (x) {
		res.push_back((int)(x % 2));
		x >>= 1;
	}
	while (res.size() < maxBit) {
		res.push_back(0);
	}
	return res;
}
vector<int> toBitSetSimple(LL x) {
	vector<int> res;
	while (x) {
		res.push_back((int)(x % 2));
		x >>= 1;
	}
	return res;
}
void input() {
	cin >> n;
	a = vector<LL>(n);
	maxBit = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		vector<int> bs = toBitSetSimple(a[i]);
		if (bs.size() > maxBit) {
			maxBit = bs.size();
		}
	}
	cin >> s;
	sp.clear();
	spb = vector<vector<int> >(maxBit);
	for (int i = 0; i < maxBit; ++i) {
		spb[i].clear();
	}
	// cout << "maxBit = " << maxBit << endl;
}

LL isInSetAnneal(LL x) {
	// cout << "isInSet(" << x << ")" << endl;
	// for (int i = 0; i < sp.size(); ++i) {
	// 	cout << sp[i] << ' ';
	// }
	// cout << endl;
	LL aa = x;
	int bitN = getBitN(aa);
	for (int ii = 0; ii < maxTimeN; ++ii) {
		for (int j = 0; j < sp.size(); ++j) {
			int newBitN = getBitN(aa ^ sp[j]);
			if (newBitN < bitN || randomDouble() < 0.5 * exp(2.0 * (bitN - newBitN))) {
				aa ^= sp[j];
				bitN = newBitN;
			}
			if (!bitN) {
				return -1;
			}
			// cout << aa << ' ' << bitN << endl;
		}
	}
	// cout << "not in set" << endl;
	return aa;
}

bool solvable(vector<int> &bs) {
	vector<vector<int> > a = spb;
	int n = bs.size();
	int m = a[0].size();
	int cur = 0;
	for (int i = 0; i < n; ++i) {
		// cout << "i = " << i << endl;
		int firstOne = -1;

		for (int j = cur; j < m; ++j) {
			if (a[i][j]) {
				firstOne = j;
				break;
			}
		}
		// cout << "here" << endl;
		if (firstOne == -1) {
			if (bs[i]) {
				return false;
			}
			continue;
		}
		// cout << "here" << endl;
		if (firstOne != cur) {
			for (int j = 0; j < n; ++j) {
				swap(a[j][firstOne], a[j][cur]);
			}
		}
		// cout << "here" << endl;

		// now we have a[i][cur] == 1
		for (int j = i + 1; j < n; ++j) {
			if (a[j][cur]) {
				for (int k = cur; k < m; ++k) {
					a[j][k] ^= a[i][k];
				}
				bs[j] ^= bs[i];
			}
		}
		// cout << "here" << endl;
		++cur;
	}
	return true;
}

bool isInSet(LL x) {
	vector<int> bs = toBitSet(x);
	return solvable(bs);
	// vector<int> piv;
	// for (int i = 0; i < bs.size(); ++i) {
	// 	if (bs[i]) {
	// 		piv.push_back(i);
	// 	}
	// }
	// vector<vector<int> > a;
	// for (int i = 0; i < piv.size(); ++i) {
	// 	a.push_back(spb[piv[i]]);
	// }
	// return solvable(a);
}
void push(LL x) {
	vector<int> bs = toBitSet(x);
	for (int i = 0; i < bs.size(); ++i) {
		spb[i].push_back(bs[i]);
	}
}

void work() {
	for (int i = n - 1; i >= 0; --i) {
		int person = s[i] - '0';
		// cout << person << ' ' << a[i] << endl;
		if (person == 0) {
			// LL mm = isInSet(a[i]);
			// if (mm != -1) {
			// 	sp.push_back(mm);
			// }
			if (!isInSet(a[i])) {
				push(a[i]);
			}
		} else {
			// LL aa = a[i];
			// if (isInSet(aa) != -1) {
			// 	cout << "1" << endl;
			// 	return ;
			// }
			if (!isInSet(a[i])) {
				cout << "1" << endl;
				return ;
			}
		}
	}
	cout << "0" << endl;
}

int main() {
	initialize_random();
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		input();
		work();
	}
	return 0;
}

Measured memory_bytes: 3788