
// 1
// 2
// 1 2
// 10

// //
// 1
// 2
// 1 1
// 10


// 1
// 6
// 2 3 4 5 6 7
// 111000

// 1
// 100
// 86 20 78 18 33 52 90 64 6 67 73 55 78 28 3 89 57 46 29 76 78 5 1 30 48 94 6 31 27 79 88 74 61 79 39 48 66 82 57 71 29 58 55 90 33 88 98 32 38 49 92 69 16 44 58 88 67 33 60 99 63 97 31 12 69 60 83 12 80 66 49 82 20 75 58 67 88 45 63 4 43 61 32 36 14 56 16 60 46 25 76 42 96 18 0 40 49 57 98 37
// 0110111000101111010101100100000111110000100000000100100111110101111011100011001110010001010000101110


// 1
// 200
// 39 15 38 71 52 97 71 57 4 13 30 49 23 8 38 54 46 69 39 82 67 5 40 13 25 44 19 87 9 62 40 77 29 2 24 79 16 57 16 39 95 55 92 77 70 72 24 1 72 97 2 87 27 42 99 97 85 72 1 13 85 49 92 27 47 75 56 51 49 98 94 76 10 5 91 86 59 50 84 12 34 18 43 42 87 44 63 92 10 80 28 6 39 82 41 6 12 70 94 9 41 27 48 91 6 10 1 6 74 46 57 43 23 81 86 29 64 33 69 51 68 13 24 36 85 17 23 40 80 92 1 31 2 19 68 8 32 89 77 18 42 10 9 4 56 34 68 79 87 56 8 67 61 24 61 7 47 7 4 83 51 96 68 32 20 50 82 18 45 69 85 38 54 42 79 89 70 72 2 22 66 54 86 52 33 78 22 72 14 50 37 56 85 59 45 17 34 95 98 30 51 70
// 110010010001000100010010110111010001101010011011010000000000101111010100010111010100111111100011110010 00111010011001000000111000101100001010010010010001001110100100101110000001011101011100100010101101



function solve(n, x, A, S, dp) {
  // console.log('n:', n, 'x:', x, 'a:', A[BigInt(S.length) - n], 's:', S[BigInt(S.length) - n])
  if (n === 0n) return x === 0n
  if (dp[n] !== undefined && dp[n][x] !== undefined) {
    // console.log('exists:', n, x, dp[n][x])
    return dp[n][x]
  }
  const p = BigInt(S.length) - n
  const s = S[p]

  let r
  if (s === '1') {
    // console.log('exec 1 do:')
    if (n - 1n === 0n) {
      r = x === 0n && (x ^ A[p]) === 0n
    } else {
      r = solve(n - 1n, x, A, S, dp) && solve(n - 1n, x ^ A[p], A, S, dp)
    }
  } else {
    // console.log('exec 0 do:')
    if (n - 1n === 0n) {
      // console.log(x, A[p], (x ^ A[p]) === 0n)
      r = x === 0n || (x ^ A[p]) === 0n
    } else {
      r = solve(n - 1n, x, A, S, dp) || solve(n - 1n, x ^ A[p], A, S, dp)
    }
  }
  if (dp[n] === undefined) {
    dp[n] = {}
  }
  // console.log(dp[n][x], n, x, r)
  dp[n][x] = r
  return r
}

function main(input) {
  const inputs = input.split('\n')
  const T = Number(inputs[0])
  for(let i = 0; i < T * 3; i+=3) {
    const N = BigInt(inputs[i + 1])
    const A = inputs[i + 2].split(' ').map(BigInt)
    const S = inputs[i + 3]
    const r = solve(N, 0n, A, S, {})
    console.log(r ? '0' : '1')
  }
  // console.log('n:', count)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

