import std.stdio;
import core.stdc.stdio;
import std.algorithm;

struct state{
	int x;
	int y;
	int z;
	int r;
}

void main(){
	while(1){

	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a==0&&b==0&&c==0)
		break;
	int m = a+b+c;
	int n;
	scanf("%d",&n);
	int[] dec = new int[m];
	dec[] = 2;
	state[] sts = new state[n];
	for(int i=0;i<n;i++){
		state s;
		scanf("%d%d%d%d",&s.x,&s.y,&s.z,&s.r);
		s.x--;
		s.y--;
		s.z--;
		if(s.r==1){
			dec[s.x] = 1;
			dec[s.y] = 1;
			dec[s.z] = 1;
		}
		sts[i] = s;
	}
	for(int _=0;_<m;_++){
		foreach(st;sts){
			if(st.r==0){
				if(dec[st.x]==1&&dec[st.y]==1)
					dec[st.z]=0;
				else if(dec[st.y]==1&&dec[st.z]==1)
					dec[st.x]=0;
				else if(dec[st.z]==1&&dec[st.x]==1)
					dec[st.y]=0;
			}
		}
	}
	foreach(d;dec)
		printf("%d\n",d);
		
	}
}