Scanf.scanf "%d" (fun t ->
    for ii = 1 to t do
        Scanf.scanf " %d" (fun n ->
            let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
            Scanf.scanf " %s" (fun s ->
                let rec loop i li =
                    if i < 0 then 0 else
                        let v = List.fold_right (fun v acc -> min acc (acc lxor v)) li a.(i) in 
                        if v = 0 then loop (i - 1) li else
                            if s.[i] = '0' then loop (i - 1) (v :: li) else 1
                in
                loop (n - 1) [] |> Printf.printf "%d\n"
            )
        )
    done
)