const chunks = [];
process.stdin.on("data", (chunk) => {
  chunks.push(chunk);
});
process.stdin.on("end", () => {
  const input = Buffer.concat(chunks).toString("utf8").trim();
  const lines = input.split("\n").map((line) => line.trim());
  const T = parseInt(lines[0], 10);
  for (let i = 0; i < T; i++) {
    const N = parseInt(lines[i * 3 + 1], 10);
    const A = lines[i * 3 + 2].split(" ").map((x) => parseInt(x, 10));
    const S = lines[i * 3 + 3];
    console.log(xorBattle(N, A, S));
  }
});

function xorBattle(N, A, S) {
  // Number that P0 can win with.
  const candidates = new Set();
  candidates.add(0);
  for (let i = N - 1; i >= 0; i--) {
    if (S[i] === "0") {
      const values = [...candidates.values()];
      for (const value of values) {
        candidates.add(value ^ A[i]);
      }
    } else {
      for (const value of candidates) {
        const theOther = value ^ A[i];
        if (!candidates.has(theOther)) {
          candidates.delete(value);
        }
      }
    }
  }
  return candidates.has(0) ? 0 : 1;
}
