local function lltonumber(str)
  local ret = 0ULL
  for i = 1, #str do
    ret = ret * 10ULL + (1ULL * str:sub(i, i):byte() - 48ULL)
  end
  return ret
end

local n = io.read("*n")
local s = {}
for i = 1, n do
  s[i] = io.read("*n") == 1
end
local t = {}
for i = 1, n do
  t[i] = io.read("*n") == 1
end
io.read()
local u = {}
do
  local str = io.read()
  local i = 1
  for w in str:gmatch("%d+") do
    u[i] = lltonumber(w)
    i = i + 1
  end
end
local v = {}
do
  local str = io.read()
  local i = 1
  for w in str:gmatch("%d+") do
    v[i] = lltonumber(w)
    i = i + 1
  end
end
local ret = {}
for i = 1, n do
  ret[i] = {}
  for j = 1, n do
    ret[i][j] = 0ULL
  end
end
local function solveStage(mul)
  local z = {}
  for i = 1, n do
    z[i] = {}
    -- -1: unknown
    for j = 1, n do
      z[i][j] = -1
    end
  end
  local need_0_row = {}
  local need_1_row = {}
  local need_0_col = {}
  local need_1_col = {}
  for i = 1, n do
    -- ROW
    local flag = u[i] % 2ULL == 1ULL
    if s[i] then
      -- OR
      if not flag then
        for j = 1, n do
          if z[i][j] == 1 then
            return false
          end
          z[i][j] = 0
        end
      else
        table.insert(need_1_row, i)
      end
    else
      -- AND
      if flag then
        for j = 1, n do
          if z[i][j] == 0 then
            return false
          end
          z[i][j] = 1
        end
      else
        table.insert(need_0_row, i)
      end
    end
    -- COLUMN
    local flag = v[i] % 2ULL == 1ULL
    if t[i] then
      -- OR
      if not flag then
        for j = 1, n do
          if z[j][i] == 1 then
            return false
          end
          z[j][i] = 0
        end
      else
        table.insert(need_1_col, i)
      end
    else
      -- AND
      if flag then
        for j = 1, n do
          if z[j][i] == 0 then
            return false
          end
          z[j][i] = 1
        end
      else
        table.insert(need_0_col, i)
      end
    end
  end
  -- refresh
  local any = false
  local function flushcol(row)
    for k = #need_0_col, 1, -1 do
      local col = need_0_col[k]
      z[row][col] = 0
      table.remove(need_0_col)
    end
    for k = #need_1_col, 1, -1 do
      local col = need_1_col[k]
      z[row][col] = 1
      table.remove(need_1_col)
    end
    for j = 1, n do
      if z[row][j] == -1 then
        z[row][j] = 0
      end
    end
    any = true
  end
  local function flushrow(col)
    for k = #need_0_row, 1, -1 do
      local row = need_0_row[k]
      z[row][col] = 0
      table.remove(need_0_row)
    end
    for k = #need_1_row, 1, -1 do
      local row = need_1_row[k]
      z[row][col] = 1
      table.remove(need_1_row)
    end
    for j = 1, n do
      if z[j][col] == -1 then
        z[j][col] = 0
      end
    end
    any = true
  end
  for i = #need_0_row, 1, -1 do
    local row = need_0_row[i]
    local found = false
    for j = 1, n do
      if z[row][j] == 0 then
        table.remove(need_0_row, i)
        found = true
        break
      end
    end
    if found then
      flushcol(row)
    end
  end
  for i = #need_1_row, 1, -1 do
    local row = need_1_row[i]
    local found = false
    for j = 1, n do
      if z[row][j] == 1 then
        table.remove(need_1_row, i)
        found = true
        break
      end
    end
    if found then
      flushcol(row)
    end
  end
  for i = #need_0_col, 1, -1 do
    local col = need_0_col[i]
    local found = false
    for j = 1, n do
      if z[j][col] == 0 then
        table.remove(need_0_col, i)
        found = true
        break
      end
    end
    if found then
      flushrow(col)
    end
  end
  for i = #need_1_col, 1, -1 do
    local col = need_1_col[i]
    local found = false
    for j = 1, n do
      if z[j][col] == 1 then
        table.remove(need_1_col, i)
        found = true
        break
      end
    end
    if found then
      flushrow(col)
    end
  end
  local remrow = #need_0_row + #need_1_row
  local remcol = #need_0_col + #need_1_col
  if any then
    for i = 1, #need_0_row do
      local row = need_0_row[i]
      for j = 1, n do
        if z[row][j] == -1 then z[row][j] = 0 end
      end
    end
    for i = 1, #need_1_row do
      local row = need_1_row[i]
      for j = 1, n do
        if z[row][j] == -1 then z[row][j] = 1 end
      end
    end
    for i = 1, #need_0_col do
      local col = need_0_col[i]
      for j = 1, n do
        if z[j][col] == -1 then z[j][col] = 0 end
      end
    end
    for i = 1, #need_1_col do
      local col = need_1_col[i]
      for j = 1, n do
        if z[j][col] == -1 then z[j][col] = 1 end
      end
    end
  elseif remrow == 0 and 0 < remcol then
    return false
  elseif remcol == 0 and 0 < remrow then
    return false
  elseif 0 < remrow and 0 < remcol then
    if #need_0_row == 0 and #need_1_row == 1 then
      if #need_1_col == 0 then
        return false
      end
      local row = need_1_row[1]
      for i = 1, #need_1_col do
        z[row][need_1_col[i]] = 1
      end
      for i = 1, #need_0_col do
        z[row][need_0_col[i]] = 0
      end
    elseif #need_0_row == 1 and #need_1_row == 0 then
      if #need_0_col == 0 then
        return false
      end
      local row = need_0_row[1]
      for i = 1, #need_1_col do
        z[row][need_1_col[i]] = 1
      end
      for i = 1, #need_0_col do
        z[row][need_0_col[i]] = 0
      end
    elseif #need_0_col == 0 and #need_1_col == 1 then
      if #need_1_row == 0 then
        return false
      end
      local col = need_1_col[1]
      for i = 1, #need_1_row do
        z[need_1_row[i]][col] = 1
      end
      for i = 1, #need_0_row do
        z[need_0_row[i]][col] = 0
      end
    elseif #need_0_col == 1 and #need_1_col == 0 then
      if #need_0_row == 0 then
        return false
      end
      local col = need_0_col[1]
      for i = 1, #need_1_row do
        z[need_1_row[i]][col] = 1
      end
      for i = 1, #need_0_row do
        z[need_0_row[i]][col] = 0
      end
    else
      local rows = {}
      local cols = {}
      for i = 1, #need_0_row do
        table.insert(rows, need_0_row[i])
      end
      for i = 1, #need_1_row do
        table.insert(rows, need_1_row[i])
      end
      for i = 1, #need_0_col do
        table.insert(cols, need_0_col[i])
      end
      for i = 1, #need_1_col do
        table.insert(cols, need_1_col[i])
      end
      for i = 1, #rows do
        for j = 1, #cols do
          local r, c = rows[i], cols[j]
          if i * j == 1 then
            z[r][c] = 1
          elseif i == 1 or j == 1 then
            z[r][c] = 0
          else
            z[r][c] = 1
          end
        end
      end
    end
  end
  for i = 1, n do
    for j = 1, n do
      assert(z[i][j] ~= -1)
      if z[i][j] == 1 then
        ret[i][j] = ret[i][j] + mul
      end
    end
  end
  return true
end
local function reduce()
  for i = 1, n do
    u[i] = u[i] / 2ULL
    v[i] = v[i] / 2ULL
  end
end
local add = 1ULL
for i = 0, 63 do
  local ret = solveStage(add)
  if not ret then
    print(-1)
    os.exit()
  end
  reduce()
  add = add * 2LL
end
for i = 1, n do
  for j = 1, n do
    local str = tostring(ret[i][j]):gsub("ULL", "")
    io.write(str)
    io.write(j == n and "\n" or " ")
  end
end
