Problem:
Score : 400 points

Problem Statement

There are two persons, numbered 0 and 1, and a variable x whose initial value is 0.
The two persons now play a game.
The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):

Person S_i does one of the following:

Replace x with x \oplus A_i, where \oplus represents bitwise XOR.

Do nothing.

Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.

Determine whether x becomes 0 at the end of the game when the two persons play optimally.

Solve T test cases for each input file.

Constraints

1 \leq T \leq 100

1 \leq N \leq 200

1 \leq A_i \leq 10^{18}

S is a string of length N consisting of 0 and 1.

All numbers in input are integers.

Input

Input is given from Standard Input in the following format.
The first line is as follows:

T

Then, T test cases follow.
Each test case is given in the following format:

N
A_1 A_2 \cdots A_N
S

Output

For each test case, print a line containing 0 if x becomes 0 at the end of the game, and 1 otherwise.

Sample Input 1

3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000

Sample Output 1

1
0
0

In the first test case, if Person 1 replaces x with 0 \oplus 1=1, we surely have x \neq 0 at the end of the game, regardless of the choice of Person 0.

In the second test case, regardless of the choice of Person 1, Person 0 can make x=0 with a suitable choice.

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

// ---------- begin scannner ----------
#[allow(dead_code)]
mod scanner {
    use std::str::FromStr;
    use std::str::SplitWhitespace;
    use std::io::Read;
    use std;
    pub struct Scanner<'a> {
        it: SplitWhitespace<'a>
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a String) -> Scanner<'a> {
            Scanner {
                it: s.split_whitespace()
            }
        }
        pub fn next<T: FromStr>(&mut self) -> T {
            match self.it.next().unwrap().parse::<T>() {
                Ok(v) => v,
                _ => panic!("Scanner error")
            }
        }
        pub fn next_chars(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}
// ---------- end scannner ----------

use std::io::Write;

fn main() {
    let sc = scanner::read_string();
    let mut sc = scanner::Scanner::new(&sc);
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    run(&mut sc, &mut out);
}

// A != 0 なので
// 最後に操作できる人が1ならどうやってもx!=0となる
// 最後に操作するのが0だとする
// 最後に操作できる空間に入らないように1が調整可能か
// 最後の0連打までは0は何も操作しないのがいい？
// ->嘘、4, 4, 2, 2 (1010)
//
// 落ち着こう、操作がA=1のみで考えよう
// これは最後に操作できる方が勝ち
//
// 1が最後に操作できるbitがあるなら1
// そうでない時は？
// 1,2,3 (110) とかは1になるがどのbitも最後に操作可能なのは0のみ
//

fn calc(x: &mut Vec<u64>) {
    if x.len() == 0 {
        return;
    }
    let mut ans = vec![];
    loop {
        let p = *x.iter().max().unwrap();
        if p == 0 {
            break;
        }
        for x in x.iter_mut().chain(ans.iter_mut()) {
            *x = std::cmp::min(*x, *x ^ p);
        }
        ans.push(p);
    }
    *x = ans;
}

fn run(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let t: usize = sc.next();
    for _ in 0..t {
        let n: usize = sc.next();
        let a: Vec<u64> = (0..n).map(|_| sc.next()).collect();
        let s: Vec<_> = sc.next_chars().into_iter().map(|d| d.to_digit(10).unwrap() as usize).collect();
        let w = 60;
        let mut x = vec![];
        let mut y = vec![];
        let mut last = vec![0; 60];
        for (&a, &d) in a.iter().zip(s.iter()).rev() {
            if d == 1 {
                y.push(a);
                for i in 0..w {
                    if a >> i & 1 == 1 {
                        last[i] = 1;
                    }
                }
            } else if (0..w).all(|k| (a >> k) & 1 == 0 || last[k] == 0) {
                x.push(a);
            }
        }
        calc(&mut x);
        let mut ans = "0";
        for y in y.iter() {
            let mut y = *y;
            for x in x.iter() {
                y = std::cmp::min(y, y ^ x);
            }
            if y != 0 {
                ans = "1";
            }
        }
        writeln!(out, "{}", ans).ok();
    }
}