#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

const vector<vector<uint64_t> > FAILURE;
template <class RandomEngine>
vector<vector<uint64_t> > solve1(int n, const vector<int> & s, const vector<int> & t, const vector<uint64_t> & u, const vector<uint64_t> & v, RandomEngine & gen) {
    vector<vector<uint64_t> > a(n, vector<uint64_t>(n));
    vector<uint64_t> row_and(n, UINT64_MAX);
    vector<uint64_t> col_and(n, UINT64_MAX);
    vector<uint64_t> row_or(n);
    vector<uint64_t> col_or(n);

    REP (y, n) {
        REP (x, n) {
            // prepare
            uint64_t must_high = 0;
            uint64_t must_low = 0;
            if (s[y] == 0) {
                must_high |= u[y];
            } else {
                must_low |= ~ u[y];
            }
            if (t[x] == 0) {
                must_high |= v[x];
            } else {
                must_low |= ~ v[x];
            }
            if (must_high & must_low) {
                return FAILURE;
            }

            // fix undetermined bits
            a[y][x] |= must_high;
            REP (i, 64) if ((1ull << i) & ~ (must_high | must_low)) {
                uint64_t bit = 1ull << i;
                bool use = bernoulli_distribution(0.5)(gen);
                if (s[y] == 0 and t[x] == 0) {
                    use = false;
                } else if (s[y] != 0 and t[x] != 0) {
                    use = true;
                } else if (x == n - 1) {
                    if (s[y] == 0) {
                        if (not (u[y] & bit) and (row_and[y] & bit)) {
                            use = false;
                        }
                    } else {
                        if ((u[y] & bit) and not (row_or[y] & bit)) {
                            use = true;
                        }
                    }
                } else if (y == n - 1) {
                    if (t[x] == 0) {
                        if (not (v[x] & bit) and (col_and[x] & bit)) {
                            use = false;
                        }
                    } else {
                        if ((v[x] & bit) and not (col_or[x] & bit)) {
                            use = true;
                        }
                    }
                }
                if (use) {
                    a[y][x] |= bit;
                }
            }

            // update
            row_and[y] &= a[y][x];
            col_and[x] &= a[y][x];
            row_or[y] |= a[y][x];
            col_or[x] |= a[y][x];

            // check
            if (x == n - 1) {
                if (u[y] != (s[y] == 0 ? row_and[y] : row_or[y])) {
                    return FAILURE;
                }
            }
            if (y == n - 1) {
                if (v[x] != (t[x] == 0 ? col_and[x] : col_or[x])) {
                    return FAILURE;
                }
            }
        }
    }
    return a;
}

chrono::high_resolution_clock::time_point clock_begin = chrono::high_resolution_clock::now();

vector<vector<uint64_t> > solve(int n, const vector<int> & s, const vector<int> & t, const vector<uint64_t> & u, const vector<uint64_t> & v) {
    constexpr int TIME_LIMIT = 1800;  // msec
    default_random_engine gen;
    while (true) {
        chrono::high_resolution_clock::time_point clock_end = chrono::high_resolution_clock::now();
        if (chrono::duration_cast<chrono::milliseconds>(clock_end - clock_begin).count() >= TIME_LIMIT) break;
        auto a = solve1(n, s, t, u, v, gen);
        if (a != FAILURE) return a;
    }
    return FAILURE;
}

// generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int N;
    cin >> N;
    vector<int> S(N), T(N);
    vector<uint64_t> U(N), V(N);
    REP (i, N) {
        cin >> S[i];
    }
    REP (i, N) {
        cin >> T[i];
    }
    REP (i, N) {
        cin >> U[i];
    }
    REP (i, N) {
        cin >> V[i];
    }
    auto ans = solve(N, S, T, U, V);
    if (ans == FAILURE) {
        cout << -1 << endl;
    } else {
        REP (j, N) {
            REP (i, N - 1) {
                cout << ans[j][i] << ' ';
            }
            cout << ans[j][N - 1] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7568