import sys sys.setrecursionlimit(500 * 500 * 2 + 1) N = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(N) : a[i] -= 1 b[i] -= 1 def INDEX(i, j, k) : return (i * N + j) * 2 + k hen = [[] for i in range(N * N * 2)] rev = [[] for i in range(N * N * 2)] for i in range(N) : r0 = c[i] % 2 r1 = c[i] // 2 for j in range(N) : hen[INDEX(a[i], j, r0)].append(INDEX(j, b[i], not r1)); rev[INDEX(j, b[i], not r1)].append(INDEX(a[i], j, r0)); hen[INDEX(j, b[i], r1)].append(INDEX(a[i], j, not r0)); rev[INDEX(a[i], j, not r0)].append(INDEX(j, b[i], r1)); visited = [False for i in range(N * N * 2)] ord = [] def dfs0(i) : visited[i] = True for j in hen[i] : if not visited[j] : dfs0(j) ord.append(i) group = [-1 for i in range(N * N * 2)] group_cnt = 0 def dfs1(i) : group[i] = group_cnt for j in rev[i] : if group[j] == -1 : dfs1(j) for i in range(N * N * 2) : if not visited[i] : dfs0(i) ord = ord[::-1] for i in ord : if group[i] == -1 : dfs1(i) group_cnt += 1 possible = True res = [[0 for j in range(N)] for i in range(N)] for i in range(N) : for j in range(N) : if group[INDEX(i, j, 0)] == group[INDEX(i, j, 1)] : possible = False res[i][j] = int(group[INDEX(i, j, 0)] < group[INDEX(i, j, 1)]) if not possible : print("-1") else : for i in range(N) : print(' '.join(map(str, res[i])))