import heapq

def main():
  n = int(input())
  S = tuple(map(int, input().split()))
  T = tuple(map(int, input().split()))
  U = tuple(map(lambda x: int(x), input().split()))
  V = tuple(map(lambda x: int(x), input().split()))

  row_or = [-1] * n
  col_or = [-1] * n
  ans = [None] * n

  # Si == 0 の時、i行目は最小でUi
  for i in range(n):
    ans[i] = ([U[i]] if S[i] == 0 else [None]) * n
    row_or[i] = U[i]

  # Tj == 0 の時、j列目は最小でVi
  for j in range(n):
    if T[i] == 1: continue

    v = V[j]
    for i in range(n):
      ans[i][j] = v & ans[i][j] if ans[i][j] else v
      col_or[j] = max(col_or[j], ans[i][j])

  for i in range(n):
    for j in range(n):
      if S[i] == 1 and T[j] == 1:
        ans[i][j] = U[i] | V[j]
      elif S[i] == 1 and row_or[i] < U[i]:
        ans[i][j] |= U[i]
        row_or[i] = ans[i][j]
        if row_or[i] > U[i]:
          print(-1)
          exit()
      elif T[j] == 1 and col_or[j] < V[j]:
        ans[i][j] |= V[j]
        col_or[j] = ans[i][j]
        if col_or[j] > V[j]:
          print(-1)
          exit()

  for row in ans:
    print(*row, sep=" ")


main()
