#include <stdio.h>

typedef unsigned long long ULL;

ULL s[500];
ULL t[500];
ULL u[500];
ULL v[500];

ULL a[500][500];

int main(int argc, char **argv)
{
    int n;

    scanf("%d", &n);

    for (int i = 0; i < n; i++) scanf(" %llu", &s[i]);
    for (int i = 0; i < n; i++) scanf(" %llu", &t[i]);
    for (int i = 0; i < n; i++) scanf(" %llu", &u[i]);
    for (int i = 0; i < n; i++) scanf(" %llu", &v[i]);

    int flag = 0;

    for (int row = 0; row < n; row++) {
        for (int col = 0; col < n; col++) {
            if (s[row] == 0 && t[col] == 0) {
                a[row][col] = u[row] | v[col];
            }
            if (s[row] == 1 && t[col] == 0) {
                a[row][col] = u[row] & v[col];
            }
            if (s[row] == 0 && t[col] == 1) {
                a[row][col] = u[row] & v[col];
            }
            if (s[row] == 1 && t[col] == 1) {
                a[row][col] = u[row] & v[col];
            }
        }
    }
    for (int row = 0; row < n; row++) {
        ULL a0 = -1;
        ULL a1 = 0;
        for (int col = 0; col < n; col++) {
            a0 &= a[row][col];
            a1 |= a[row][col];
        }
        if (s[row] == 0 && u[row] != a0) flag = 1;
        if (s[row] == 1 && u[row] != a1) flag = 1;
    }
    for (int col = 0; col < n; col++) {
        ULL a0 = -1;
        ULL a1 = 0;
        for (int row = 0; row < n; row++) {
            a0 &= a[row][col];
            a1 |= a[row][col];
        }
        if (t[col] == 0 && v[col] != a0) flag = 1;
        if (t[col] == 1 && v[col] != a1) flag = 1;
    }
    if (flag == 1)
        printf("-1\n");
    else {
        for (int row = 0; row < n; row++) {
            for (int col = 0; col < n; col++) {
                printf("%llu ", a[row][col]);
            }
            printf("\n");
        }
    }
    return 0;
}