#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define sint(n) scanf("%d",&n);

using namespace std;


int main(){
	while(1){
		int a,b,c;
		sint(a)
		sint(b)
		sint(c)
		
		if(a==0){break;}
		int k;
		sint(k)
		
		int buhin[301]={0};
		rep(i,301){
			buhin[i]=2;
		}
		
		int e[1000],r[1000],t[1000],u[1000];
		rep(i,k){
			scanf("%d%d%d%d",&e[i],&r[i],&t[i],&u[i]);
			if(u[i]==1){
				buhin[e[i]]=buhin[r[i]]=buhin[t[i]]=1;
			}
		}
		
		
		rep(i,k){
			if(u[i]==0){
				if(buhin[e[i]]==1 && buhin[r[i]]==1){
					buhin[t[i]]=0;
				}
				if(buhin[e[i]]==1 && buhin[t[i]]==1){
					buhin[r[i]]=0;
				}
				if(buhin[t[i]]==1 && buhin[r[i]]==1){
					buhin[e[i]]=0;
				}
			}
		}
		
		rep(i,a+b+c){
			printf("%d\n",buhin[i+1]);
		}
	}
}
/*
2 2 2
4
2 4 5 0
2 3 6 0
1 4 5 0
2 3 5 1 
*/
#include <iostream>
using namespace std;
struct results{
        int a;
        int b;
        int c;
        int result;
};
int main(){
        while(true){
        int parts[1000]={0};
        int aa,bb,cc,n;
        cin >> aa >> bb >> cc;
        if(aa+bb+cc==0)
                break;
        cin >> n;
        results data[1000];
        for( int i=0 ; i<n ; i++ )
                cin >> data[i].a >> data[i].b >> data[i].c >> data[i].result;
        for( int all_counter=0 ; all_counter<2 ; all_counter++)
        for( int i=0 ; i<n ; i++ ){
                if(data[i].result){
                        parts[data[i].a]=1;
                        parts[data[i].b]=1;
                        parts[data[i].c]=1;
                }
                else{
                        int level=parts[data[i].a]+parts[data[i].b]+parts[data[i].c];
                        if(level>1){
                                parts[data[i].a]==0?parts[data[i].a]=-1:0;
                                parts[data[i].b]==0?parts[data[i].b]=-1:0;
                                parts[data[i].c]==0?parts[data[i].c]=-1:0;
                        }
                }
        }
        for( int i=0+1 ; i<=aa+bb+cc ; i++ )
                if(parts[i]==-1)
                        cout << 0 << endl;
                else if(parts[i]==0)
                        cout << 2 << endl;
                else
                        cout << 1 << endl;
        }
        return 0;
}