package main
import (
"bufio"
"fmt"
"os"
)
func scanUint64(scanner *bufio.Scanner) uint64 {
scanner.Scan()
b := scanner.Bytes()
var res uint64
for _, ch := range b {
res = res*10 + uint64(ch-'0')
}
return res
}
func scanInt(scanner *bufio.Scanner) int {
scanner.Scan()
b := scanner.Bytes()
var res int
for _, ch := range b {
res = res*10 + int(ch-'0')
}
return res
}
func scanString(scanner *bufio.Scanner) string {
scanner.Scan()
return scanner.Text()
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
scanner.Buffer(make([]byte, 1024*1024), 10*1024*1024)
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
if !scanner.Scan() {
return
}
tBytes := scanner.Bytes()
var t int
for _, ch := range tBytes {
t = t*10 + int(ch-'0')
}
for tc := 0; tc < t; tc++ {
n := scanInt(scanner)
a := make([]uint64, n)
for i := 0; i < n; i++ {
a[i] = scanUint64(scanner)
}
b := make([]uint64, n)
for i := 0; i < n; i++ {
b[i] = scanUint64(scanner)
}
c := scanString(scanner)
var X uint64 = 0
for i := 0; i < n; i++ {
X ^= a[i]
}
basis := make([]uint64, 60)
owner := make([]int, 60)
for i := n - 1; i >= 0; i-- {
v := a[i] ^ b[i]
player := int(c[i] - '0')
for bit := 59; bit >= 0; bit-- {
if (v>>bit)&1 == 1 {
if basis[bit] == 0 {
basis[bit] = v
owner[bit] = player
break
} else {
v ^= basis[bit]
}
}
}
}
for bit := 59; bit >= 0; bit-- {
if basis[bit] != 0 {
if owner[bit] == 1 && ((X>>bit)&1) == 0 {
X ^= basis[bit]
} else if owner[bit] == 0 && ((X>>bit)&1) == 1 {
X ^= basis[bit]
}
}
}
fmt.Fprintln(out, X)
}
}