from collections import deque, defaultdict def scc(N, G, RG): order = [] seen = [0]*N group = [None]*N def dfs(s): task = deque([(s, 1), (s, 0)]) while task: v, t = task.pop() if t: if seen[v] == 2: continue seen[v] = 2 order.append(v) else: if seen[v]: continue seen[v] = 1 for e in G[v]: if not seen[e]: task.append((e, 1)) task.append((e, 0)) def rdfs(s, col): task = deque([s]) while task: v = task.pop() if seen[v]: continue seen[v] = 1 group[v] = col for e in RG[v]: if not seen[e]: task.append(e) for i in range(N): if not seen[i]: dfs(i) seen = [0]*N label = 0 for s in reversed(order): if not seen[s]: rdfs(s, label) label += 1 return label, group N = int(input()) S = list(map(lambda x: int(x)-1, input().split())) T = list(map(lambda x: int(x)-1, input().split())) U = list(map(int, input().split())) graph = defaultdict(list) rgraph = defaultdict(list) for i in range(N): for j in range(N): s, t, u = S[i], T[i], U[i] x = s*N+j y = j*N+t nx = x+N**2*(u % 2) ny = y+N**2*(u//2) graph[nx].append((ny+N**2) % (2*N**2)) rgraph[(ny+N**2) % (2*N**2)].append(nx) graph[ny].append((nx+N**2) % (2*N**2)) rgraph[(nx+N**2) % (2*N**2)].append(ny) M, sccgraph = scc(2*N**2, graph, rgraph) ans = [[0]*N for _ in range(N)] for i in range(N): for j in range(N): n = i*N+j if sccgraph[n] == sccgraph[n+N**2]: print(-1) exit() elif sccgraph[n] > sccgraph[n+N**2]: ans[i][j] = 1 for a in ans: print(*a)