#include <stdio.h>
#include <inttypes.h>

static uint32_t x=123456789;
static uint32_t y=362436069;
static uint32_t z=521288629;
static uint32_t w=88675123;

void seed(uint32_t a,uint32_t b,uint32_t c,uint32_t d) {
	if((a|b|c|d)==0)return;
	x=a;y=b;z=c;w=d;
}

uint32_t randint(void) {
	uint32_t t;
	t=(x^(x<<11));
	x=y;y=z;z=w;
	w=(w^(w>>19))^(t^(t>>8));
	return w;
}

uint64_t randint64(void) {
	return ((uint64_t)randint() << 32) | randint();
}

int N;
int S[512];
int T[512];
uint64_t U[512];
uint64_t V[512];

uint64_t must[512][512];
uint64_t dont[512][512];

uint64_t want_row[512], want_col[512];
uint64_t notall_row[512], notall_col[512];

uint64_t test[512][512];

int main(void) {
	int i, j;
	int attempt;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &S[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		if (scanf("%d", &T[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNu64, &U[i]) != 1) return 1;
	}
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNu64, &V[i]) != 1) return 1;
	}

	for (i = 0; i < N; i++) {
		if (S[i] == 0) {
			for (j = 0; j < N; j++) must[i][j] |= U[i];
		} else {
			for (j = 0; j < N; j++) dont[i][j] |= ~U[i];
		}
	}
	for (j = 0; j < N; j++) {
		if (T[j] == 0) {
			for (i = 0; i < N; i++) must[i][j] |= V[j];
		} else {
			for (i = 0; i < N; i++) dont[i][j] |= ~V[j];
		}
	}

	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (must[i][j] & dont[i][j]) {
				puts("-1");
				return 0;
			}
		}
	}

	for (i = 0; i < N; i++) {
		if (S[i] == 0) notall_row[i] = ~U[i]; else want_row[i] = U[i];
		for (j = 0; j < N; j++) {
			want_row[i] &= ~must[i][j];
			notall_row[i] &= ~dont[i][j];
		}
	}

	for (j = 0; j < N; j++) {
		if (T[j] == 0) notall_col[j] = ~V[i]; else want_col[j] = V[i];
		for (i = 0; i < N; i++) {
			want_col[j] &= ~must[i][j];
			notall_col[j] &= ~dont[i][j];
		}
	}

	for (attempt = 0; attempt < 10000; attempt++) {
		int ok = 1;
		for (i = 0; i < N; i++) {
			for (j = 0; j < N; j++) test[i][j] = (randint64() | must[i][j]) & ~dont[i][j];
		}
		for (i = 0; ok && i < N; i++) {
			uint64_t ando = test[i][0], oa = test[i][0];
			for (j = 0; j < N; j++) {
				ando &= test[i][j];
				oa |= test[i][j];
			}
			if ((S[i] == 0 ? ando : oa) != U[i]) ok = 0;
		}
		for (j = 0; ok && j < N; j++) {
			uint64_t ando = test[0][j], oa = test[0][j];
			for (i = 0; i < N; i++) {
				ando &= test[i][j];
				oa |= test[i][j];
			}
			if ((T[j] == 0 ? ando : oa) != V[j]) ok = 0;
		}
		if (ok) {
			for (i = 0; i < N; i++) {
				printf("%" PRIu64, test[i][0]);
				for (j = 1; j < N; j++) printf(" %" PRIu64, test[i][j]);
				putchar('\n');
			}
			return 0;
		}
	}

	puts("-1");
	return 0;
}

/*

論理積制約 → 少なくともそれが全部1、「補集合が全部1」になってはいけない
論理和制約 → 少なくとも補集合が全部0、「それが全部0」になってはいけない

*/
