import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def SCC(N, G, RG): order = [] used = [0]*N group = [None]*N def dfs(s): used[s] = 1 for t in G[s]: if not used[t]: dfs(t) order.append(s) def rdfs(s, col): group[s] = col used[s] = 1 for t in RG[s]: if not used[t]: rdfs(t, col) for i in range(N): if not used[i]: dfs(i) used = [0]*N label = 0 for s in reversed(order): if not used[s]: rdfs(s, label) label += 1 return label, group def solve(): n = ni() s = [x-1 for x in nl()] t = [x-1 for x in nl()] u = nl() m = 2 * n ** 2 G = [list() for _ in range(m)] rG = [list() for _ in range(m)] for i in range(n): cs, ct, cu = s[i], t[i], u[i] for j in range(n): x = [cs * n + j, cs * n + j + n**2] y = [j * n + ct, j * n + ct + n**2] G[x[cu & 1]].append(y[(cu >> 1) ^ 1]) rG[y[(cu >> 1) ^ 1]].append(x[cu & 1]) G[y[cu >> 1]].append(x[cu & 1 ^ 1]) rG[x[cu & 1 ^ 1]].append(y[cu >> 1]) _, gr = SCC(m, G, rG) ret = [0]*n**2 for i in range(n**2): if gr[i] == gr[i+n**2]: print(-1) return ret[i] = int(gr[i] > gr[i+n**2]) for i in range(n): print(*ret[i*n:(i+1)*n]) return solve()