import qualified Data.ByteString.Char8 as B
import           Data.Maybe (fromJust)
import           Control.Monad.State.Strict
import qualified Data.Set as S
import           Data.Bits (xor)

main :: IO ()
main = do
  t <- getInt
  replicateM_ t testCase

testCase :: IO ()
testCase = do
  n <- getInt
  as <- reverse . fmap (fst . fromJust . B.readInt) . B.words <$> B.getLine
  s <- reverse <$> getLine
  putStrLn
    $ if solve s as (S.singleton 0)
      then "0"
      else "1"

solve _ _ e
  | null e = False
solve "0" [h] acc = 0 `elem` acc || 0 `xor` h `elem` acc
solve "1" [h] acc = 0 `elem` acc && 0 `xor` h `elem` acc
solve ('0':rest) (h:t) acc = let s = acc `S.union` (S.map (`xor` h) acc)
                             in solve rest t s
solve ('1':rest) (h:t) acc = let s = S.filter (\n -> n `xor` h `elem` acc) acc
                             in solve rest t s

getInt = fst . fromJust . B.readInt <$> B.getLine
