import Foundation


func solution(_ N: Int, _ A: [Int], _ S: [Int]) {
   var x = 0
   
   for tmp in 0 ..< N {
      let player = S[tmp]
      let useingA = A[tmp]
      
      if player == 1 && (x ^ useingA) != 0 {
         x ^= useingA
      }
      
      if player == 1 && (x ^ useingA) == 0 {
         return
      }
      
      if player == 0 && (x ^ useingA) != 0 {
         return
      }
      
      if player == 0 && (x ^ useingA) == 0 {
         x ^= useingA
      }
      
   }
   
   print(x)
}


func Intput(N: Int) {
   for _ in 0 ..< N {
      let N = Int(readLine()!)!
      let A = readLine()!.components(separatedBy: " ").map { Int($0)! }
      let S = readLine()!.map { String($0) }.map { Int($0)! }
      solution(N, A, S)
   }
}

let N = Int(readLine()!)!

Intput(N: N)

