import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.min

fun main() {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    for (c in 1..jin.readLine().toInt()) {
        val n = jin.readLine().toInt()
        val masks = jin.readLine().split(" ").map { it.toLong() }
        val turns = jin.readLine()
        val reduced = mutableListOf<Long>()
        var answer = 0
        for (j in n - 1 downTo 0) {
            var mask = masks[j]
            for (v in reduced) {
                mask = min(mask, mask xor v)
            }
            if (mask != 0L) {
                if (turns[j] == '0') {
                    reduced.add(mask)
                } else if (turns[j] == '1') {
                    answer = 1
                    break
                }
            }
        }
        println(answer)
    }
}