import Data.Bits

toInt = (read :: String -> Int)
readIntLine = getLine >>= return . toInt

main = do
    t <- readIntLine
    mapM (\x -> qestion) [1..t]

qestion = do
    n <- readIntLine
    as <- getLine >>= return . map toInt . words
    s <- getLine 
    q as s

q as s = do
    print $ if xor one zero == 0 then 0 else 1
    where
        one = foldl (.|.) 0 $ map snd $ filter (\x -> fst x == '1') ns
        zero = foldl (.|.) 0 $ map snd $ filter (\x -> fst x == '0') ns
        ns = zip s as

