program xor_battle
  implicit none
  integer :: t, n, m, i, j, k
  integer(8) :: a(200) = 0, b(200) = 0, x
  character(200) :: s
  read(*,*) t
  do k = 1, t
    read(*,*) n
    read(*,*) a(1:n)
    read(*,*) s
    m = 0
    b = 0
    do i = n, 1, -1
      x = a(i)
      do j = 1, m
        x = min(x, xor(x, b(j)))
      end do
      if (x > 0) then
        if (s(i:i) == '0') then
          m = m + 1
          b(m) = x
        else
          write(*,'(i0)') 1
          goto 100
        end if
      end if
    end do
    write(*,'(i0)') 0
  100 end do
end program xor_battle