local function check(x, vec)
  local w = {}
  for i = 1, #vec do
    w[i] = vec[i]
  end
  local isok = true
  for i = 1, 62 do
    local rmpos = 0
    for j = #w, 1, -1 do
      if w[j] % 2 == 1 then
        rmpos = j
        break
      end
    end
    if rmpos == 0 then
      if x % 2 == 1 then
        isok = false
        break
      end
    else
      local v = w[rmpos]
      table.remove(w, rmpos)
      if x % 2 == 1 then
        x = v ~ x
      end
      for j = 1, #w do
        if w[j] % 2 == 1 then
          w[j] = v ~ w[j]
        end
      end
    end
    x = x // 2
    for j = 1, #w do
      w[j] = w[j] // 2
    end
  end
  return isok
end
local q = io.read("*n")
for iq = 1, q do
  local n = io.read("*n", "*l")
  local as = io.read()
  local a = {}
  for ac in as:gmatch("%d+") do
    table.insert(a, tonumber(ac))
  end
  local s = io.read()
  local t = {}
  local valid = true
  for i = n, 1, -1 do
    if s:sub(i, i) == "0" then
      table.insert(t, a[i])
    else
      if not check(a[i], t) then
        valid = false break
      end
    end
  end
  print(valid and 0 or 1)
end