#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_V = 500 * 500 * 2 + 10;
vector<int> g[MAX_V];
vector<int> r[MAX_V];


const int MAX_N = 505;
int A[MAX_N][MAX_N];
int N;
int nodeId(int r, int c, int f) {
  return (r * N + c) * 2 + f;
}

int sccid[MAX_V];
int sccnum;
void dfs(int p, vector<int>& order) {
  if (sccid[p] != 0) return;
  sccid[p] = 1;
  for (int i : g[p]) dfs(i, order);
  order.push_back(p);
}
void rdfs(int p, int id) {
  if (sccid[p] != -1) return;
  sccid[p] = id;
  for (int i : r[p]) rdfs(i, id);
}
void scc() {
  vector<int> order;
  CLR(sccid, 0);
  REP(i, 2*N*N) dfs(i, order);
  CLR(sccid, -1);
  sccnum = 0;
  for (int i = (int)order.size() - 1; i >= 0; i--) if (sccid[order[i]] == -1) {
    rdfs(order[i], sccnum);
    sccnum++;
  }
}


int main2() {
  REP(i, MAX_V) g[i].clear();
  REP(i, MAX_V) r[i].clear();

  N = nextLong();

  vector<int> S(N), T(N), U(N);
  REP(i, N) S[i] = nextLong()-1;
  REP(i, N) T[i] = nextLong()-1;
  REP(i, N) U[i] = nextLong();


  REP(i, N) REP(j, N) {
    int a = nodeId(S[i], j, U[i] & 1);
    int b = nodeId(j, T[i], U[i] >> 1);
    g[b].push_back(a^1);
    g[a].push_back(b^1);
    r[a^1].push_back(b);
    r[b^1].push_back(a);
  }

  scc();

  // REP(i, N*N) cout << sccid[i * 2] << " "; cout << endl;
  // REP(i, N*N) cout << sccid[i * 2 + 1] << " "; cout << endl;

  bool ng = false;
  REP(r, N) REP(c, N) {
    if (sccid[nodeId(r, c, 0)] != -1 && sccid[nodeId(r, c, 0)] == sccid[nodeId(r, c, 1)]) {
      ng = true;
    }
  }
  if (ng) {
    cout << -1 << endl;
  } else {

    REP(i, N*N) {
      int r = i / N;
      int c = i % N;
      A[r][c] = (sccid[nodeId(r, c, 1)] > sccid[nodeId(r, c, 0)]) ? 1 : 0;
    }

    REP(r, N) {
      REP(c, N) {
        if (c) cout << ' ';
        cout << A[r][c];
      }
      cout << '\n';
    }
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}