#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int ans[500];
int a, b, c, N;
int r[1000], x[1000], y[1000], z[1000];

void init() {
   for (int i = 0; i < 500; i++) ans[i] = 2;
}

int main() {
   while (cin >> a >> b >> c, a) {
      init();
      cin >> N;
      for (int i = 0; i < N; i++) {
         cin >> x[i] >> y[i] >> z[i] >> r[i];
         if (r[i] == 1) ans[x[i]] = 1, ans[y[i]] = 1, ans[z[i]] = 1;
      }
      
      for (int i = 0; i < N; i++) {
         if (r[i] == 1) continue;
         if (ans[x[i]] == 1 && ans[y[i]] == 1) ans[z[i]] = 0;
         if (ans[y[i]] == 1 && ans[z[i]] == 1) ans[x[i]] = 0;
         if (ans[z[i]] == 1 && ans[x[i]] == 1) ans[y[i]] = 0;
      }

      for (int i = 1; i <= a+b+c; i++) {
         cout << ans[i] << endl;
      }
   }

   return 0;
}
