#include<iostream>
using namespace std;

int main(){

  int a, b, c, n;
  int p[1111], m[1111], k[1111], q[1111];
  int data[333];

  while(cin >> a >> b >> c, a){
    for(int i=332;i;) data[i--] = 2;
    
    cin >> n;
    for(int i=0;i<n;i++) cin >> p[i] >> m[i] >> k[i] >> q[i];
    
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(q[j]) data[p[j]] = data[m[j]] = data[k[j]] = q[j];
	else{
	  if(data[p[j]] == 1 && data[m[j]] == 1) data[k[j]] = 0;
	  if(data[m[j]] == 1 && data[k[j]] == 1) data[p[j]] = 0;
	  if(data[p[j]] == 1 && data[k[j]] == 1) data[m[j]] = 0;
	}
      }
    }
    for(int i=1;i<=a+b+c;i++) cout << data[i] << endl;
  }
  
}