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 stack = [i] head = [0] while len(stack) : i = stack[-1] if head[-1] == len(hen[i]) : stack.pop(-1) head.pop(-1) ord.append(i) else : j = hen[i][head[-1]] head[-1] += 1 if not visited[j] : visited[j] = True stack.append(j) head.append(0) group = [-1 for i in range(N * N * 2)] group_cnt = 0 def dfs1(i) : group[i] = group_cnt stack = [i] head = [0] while len(stack) : i = stack[-1] if head[-1] == len(rev[i]) : stack.pop(-1) head.pop(-1) else : j = rev[i][head[-1]] head[-1] += 1 if group[j] == -1 : stack.append(j) head.append(0) group[j] = group_cnt 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])))