program xor_battle
  implicit none
  integer :: t, n, i, j, k, cnt(0:1)
  integer(8) :: a(200) = 0, b(200, 0:1)
  character(200) :: s
  logical :: f
  read(*,*) t
  do k = 1, t
    read(*,*) n
    read(*,*) a(1:n)
    read(*,*) s
    cnt = 0
    b = 0
    do i = 1, n
      j = ichar(s(i:i)) - 48
      cnt(j) = cnt(j) + 1
      b(cnt(j), j) = a(i)
    end do
    if (any(cnt == 0)) then
      write(*,'(i0)') merge(1, 0, cnt(0) == 0)
      cycle
    end if
    cnt(0) = reduce(b(1:cnt(0), 0))
    cnt(1) = reduce(b(1:cnt(1), 1))
    f = .true.
    do i = 1, cnt(1)
      do j = 1, cnt(0)
        if (b(j, 0) == b(i, 1)) goto 100
      end do
      f = .false.
      goto 200
    100 end do
    200 write(*,'(i0)') merge(0, 1, f)
  end do
contains
  integer function reduce(x) result(res)
    integer(8), intent(inout) :: x(:)
    integer :: n, i, j, k, l
    n = size(x)
    j = 0
    do i = 1, n
      do while (j <= 63 .and. all(.not.btest(x(i:n), j)))
        j = j + 1
      end do
      if (j > 63) then
        res = i - 1
        return
      end if
      if (.not.btest(x(i), j)) then
        do k = i + 1, n
          if (btest(x(k), j)) then
            l = k
            exit
          end if
        end do
        call swap(x(i), x(l))
      end if
      do k = 1, n
        if (k == i) cycle
        if (btest(x(k), j)) x(k) = xor(x(k), x(i))
      end do
    end do
    res = n
  end
  subroutine swap(a, b)
    integer(8), intent(inout) :: a, b
    a = xor(a, b)
    b = xor(a, b)
    a = xor(a, b)
  end
end program xor_battle