package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var T, N int
  var A, C []int
  var B [][]int
  var S string
  NextInt(&T)
  for test := 0; test < T; test++ {
    NextInt(&N)
    NextIntVec(&A)
    S = NextLine()
    B = make([][]int, N)
    for i, a := range A {
      B[i] = make([]int, 60)
      for j := range B[i] {
        B[i][j] = a % 2
        a /= 2
      }
    }
    F := func(a int) bool {
      M := make([][]int, 60)
      X := make([]int, 60)
      for i := range M {
        M[i] = make([]int, len(C))
        for j := range M[i] { M[i][j] = B[C[j]][i] }
        X[i] = B[a][i]
      }
      for i, j := 0, 0; i < 60 && j < len(C); i, j = i + 1, j + 1 {
        for j < len(C) && M[i][j] == 0 {
          for p := i + 1; p < 60; p++ {
            if M[p][j] == 0 { continue }
            M[i], M[p] = M[p], M[i]
            X[i], X[p] = X[p], X[i]
            break
          }
          if M[i][j] == 0 { j++ }
        }
        if j == len(C) { break }
        for k := range M {
          if k == i { continue }
          m := M[k][j]
          for l := range M[k] { M[k][l] ^= M[i][l] * m }
          X[k] ^= X[i] * m
        }
      }
      ret := true
      for i, j := 0, 0; i < 60; i, j = i + 1, j + 1 {
        for j < len(C) && M[i][j] == 0 { j++ }
        ret = ret && (j < len(C) || X[i] == 0)
      }
      return ret
    }
    C = make([]int, 0)
    ans := 0
    for i := N - 1; 0 <= i; i-- {
      s := int(S[i]) - int('0')
      if s == 0 {
        C = append(C, i)
      } else if !F(i) {
        ans = 1; break
      }
    }
    Write(ans)
  }
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 5928