import sys sys.setrecursionlimit(10000000) MOD = 10 ** 9 + 7 INF = 10 ** 15 class StronglyConnectedComponents: def __init__(self,N): self.N = N self.G = [[] for _ in range(self.N)] self.rG = [[] for _ in range(self.N)] self.group = [1] * self.N self.order = [] def add_edge(self,u,v): # u -> v self.G[u].append(v) self.rG[v].append(u) def build(self): stack = [] for s in range(self.N): if self.group[s] > 0: stack.append(s + 1) while stack: v = stack.pop() if v < 0: self.order.append(- v - 1) else: if self.group[v - 1] > 0: stack.append(-v) self.group[v - 1] = -1 for e in self.G[v - 1]: stack.append(e + 1) cnt = 0 for s in self.order[::-1]: if self.group[s] < 0: stack.append(s) self.group[s] = cnt while stack: v = stack.pop() for e in self.rG[v]: if self.group[e] < 0: self.group[e] = cnt stack.append(e) cnt += 1 def __getitem__(self,i): if 0 <= i < self.N: return self.group[i] else: raise ValueError("StrongglyConnectedComponents index out of range") def main(): N = int(input()) S = list(map(int,input().split())) T = list(map(int,input().split())) U = list(map(int,input().split())) M = N*N scc = StronglyConnectedComponents(2*M) for s,t,u in zip(S,T,U): s -= 1 t -= 1 if u == 0: for i in range(N): scc.add_edge(N*s + i,N*i + t + M) scc.add_edge(N*i + t,N*s + i + M) elif u == 1: for i in range(N): scc.add_edge(N*s + i + M,N*i + t + M) scc.add_edge(N*i + t,N*s + i) elif u == 2: for i in range(N): scc.add_edge(N*s + i,N*i + t) scc.add_edge(N*i + t + M,N*s + i + M) else: for i in range(N): scc.add_edge(N*s + i + M,N*i + t) scc.add_edge(N*i + t + M,N*s + i) scc.build() ans = [[0]*N for _ in range(N)] for i in range(N): for j in range(N): a = scc[N*i + j] b = scc[N*i + j + M] if a == b: print(-1) return elif a < b: ans[i][j] = 1 for a in ans: print(*a) if __name__ == '__main__': main()