import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

immutable int B = 64;
bool ok = true;

bool[] toArray(ulong n) {
    auto res = new bool[](B);
    foreach (i; 0..B) res[i] = (n >> i) & 1;
    return res;
}

ulong toUlong(int[] a) {
    ulong n = 0;
    foreach (i, b; a) n |= (b << i);
    return n;
}

bool[][] solve(int N, int[] S, int[] T, bool[] U, bool[] V) {
    int[][] A = new int[][](N, N);
    foreach (ref a; A) a[] = -1;

    foreach (i; 0..N) {
        if (S[i] == 0 && U[i] == 1) {
            foreach (j; 0..N) {
                if (A[i][j] == 0) {
                    writeln(-1);
                    exit(0);
                }
                A[i][j] = 1;
            }
        } else if (S[i] == 1 && U[i] == 0) {
            foreach (j; 0..N) {
                if (A[i][j] == 1) {
                    writeln(-1);
                    exit(0);
                }
                A[i][j] = 0;
            }
        }
    }

    foreach (j; 0..N) {
        if (T[j] == 0 && V[j] == 1) {
            foreach (i; 0..N) {
                if (A[i][j] == 0) {
                    writeln(-1);
                    exit(0);
                }
                A[i][j] = 1;
            }
        } else if (T[j] == 1 && V[j] == 0) {
            foreach (i; 0..N) {
                if (A[i][j] == 1) {
                    writeln(-1);
                    exit(0);
                }
                A[i][j] = 0;
            }
        }
    }


    int par = 0;

    foreach (i; 0..N) {
        int cnt0, cnt1, cnt2;
        int idx = -1;
        foreach (j; 0..N) {
            if (A[i][j] == 0) cnt0 += 1;
            else if (A[i][j] == 1) cnt1 += 1;
            else cnt2 += 1, idx = j;
        }
        if (cnt2 == 0) continue;
        if (cnt2 == 1) {
            if (S[i] == 0 && cnt0 == 0) {
                A[i][idx] = 0;
            } else if (S[i] == 1 && cnt1 == 0) {
                A[i][idx] = 1;
            }
        } else {
            int p = par;
            par ^= 1;
            foreach (j; 0..N) if (A[i][j] == -1) A[i][j] = p, p ^= 1;
        }
    }

    foreach (j; 0..N) {
        int cnt0, cnt1, cnt2;
        int idx = -1;
        foreach (i; 0..N) {
            if (A[i][j] == 0) cnt0 += 1;
            else if (A[i][j] == 1) cnt1 += 1;
            else cnt2 += 1, idx = i;
        }
        if (cnt2 == 0) continue;
        if (cnt2 == 1) {
            if (T[j] == 0 && cnt0 == 0) {
                A[idx][j] = 0;
            } else if (T[j] == 1 && cnt1 == 0) {
                A[idx][j] = 1;
            }
        } else {
            int p = par;
            par ^= 1;
            foreach (i; 0..N) if (A[i][j] == -1) A[i][j] = p, p ^= 1;
        }
    }

    foreach (i; 0..N) foreach (j; 0..N) if (A[i][j] == -1) A[i][j] = par, par ^= 1;

    return A.map!(a => a.map!(to!bool).array).array;
}
void main() {
    auto N = readln.chomp.to!int;
    auto S = readln.split.map!(to!int).array;
    auto T = readln.split.map!(to!int).array;
    auto U = readln.split.map!(a => a.to!ulong.toArray).array;
    auto V = readln.split.map!(a => a.to!ulong.toArray).array;

    auto A = new ulong[][](N, N);

    foreach (b; 0..B) {
        auto res = solve(N, S, T, U.map!(a => a[b]).array, V.map!(a => a[b]).array);
        foreach (i; 0..N) foreach (j; 0..N) A[i][j] |= (res[i][j] << b);
    }

    foreach (a; A) a.map!(to!string).join(" ").writeln;
}