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

#define rep(i, n) for(int i=0; i<n; i++)

int N;
int a, b, c;
int x[1111], y[1111], z[1111], r[1111];
int state[333];

int main()
{
  while(cin >> a >> b >> c, a){
    int n = a + b + c;
    cin >> N;
    rep(i, N) cin >> x[i] >> y[i] >> z[i] >> r[i];
    rep(i, N) x[i] -= 1;
    rep(i, N) y[i] -= 1;
    rep(i, N) z[i] -= 1;

    rep(i, n) state[i] = 2;
    rep(i, N) if( r[i]) state[x[i]] = state[y[i]] = state[z[i]] = 1;
    rep(i, N) if(!r[i]){
      if(state[x[i]] == 1 && state[y[i]] == 1){ state[z[i]] = 0;  continue; }
      if(state[y[i]] == 1 && state[z[i]] == 1){ state[x[i]] = 0;  continue; }
      if(state[z[i]] == 1 && state[x[i]] == 1){ state[y[i]] = 0;  continue; }
    }

    rep(i, n) printf("%d\n", state[i]);
  }

  return 0;
}