#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  long long s[N];
  long long t[N];
  long long u[N];
  long long v[N];
  for (int i = 0; i < N; ++i)
    cin >> s[i];
  for (int i = 0; i < N; ++i)
    cin >> t[i];
  for (int i = 0; i < N; ++i)
    cin >> u[i];
  for (int i = 0; i < N; ++i)
    cin >> v[i];

  int ret[N][N];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (s[i] == 1) {
        if (t[j] == 1) {
          ret[i][j] = u[i] | v[j];
        } else {
          ret[i][j] = u[i] & v[j];
        }
      } else {
        if (t[j] == 1) {
          ret[i][j] = u[i] & v[j];
        } else {
          ret[i][j] = u[i] | v[j];
        }
      }
    }
  }

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (j != 0)
        cout << " ";
      cout << ret[i][j];
    }
    cout << endl;
  }


  return 0;
}