fun main() {
    val builder = StringBuilder()

    val t = readInputLine().toInt()

    repeat(t) {
        val n = readInputLine().toInt()
        val aArr = readInputLine().split(" ").map { it.toLong() }
        val s = readInputLine().toCharArray()

        val dp = Array(n + 1) { mutableSetOf<Long>() }

        dp[n].add(0L)

        for (i in n - 1 downTo 0) {
            when(s[i]) {
                '0' -> {
                    dp[i] = dp[i + 1].toMutableSet()
                    var tmp = aArr[i]

                    for (b in dp[i + 1]) {
                        if (tmp xor b < tmp) {
                            tmp = tmp xor b
                        }
                    }

                    if (tmp != 0L) {
                        dp[i].add(tmp)
                    }
                }
                else -> {
                    var tmp = aArr[i]

                    for (b in dp[i + 1]) {
                        if (tmp xor b < tmp) {
                            tmp = tmp xor b
                        }
                    }

                    if (tmp == 0L) {
                        dp[i] = dp[i + 1].toMutableSet()
                    }
                }
            }
        }

        if (dp[0].contains(0L)) {
            builder.appendln(0)
        } else {
            builder.appendln(1)
        }
    }

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
