#include <iostream>
#include <algorithm>
using namespace std;

int main(void){
	int a,b,c;
	
	while(cin>>a>>b>>c && (a||b||c)){
		int i,n;
		cin>>n;
		
		int res[a+b+c+1];
		int tmp[n][3];
		fill(res,res+a+b+c+1,2);
		
		for(i=0;i<n;i++){
			int I,J,K,R;
			cin>>I>>J>>K>>R;
			if(R == 1){
				res[I] = res[J] = res[K] = 1;
				i--;
				n--;
			}
			else{
				tmp[i][0] = I;
				tmp[i][1] = J;
				tmp[i][2] = K;
			}
		}
		int size = i;
		for(i=0;i<size;i++){
			if(res[tmp[i][0]] == 1 && res[tmp[i][1]] == 1) res[tmp[i][2]] = 0;
			else if(res[tmp[i][0]] == 1 && res[tmp[i][2]] == 1) res[tmp[i][1]] = 0;
			else if(res[tmp[i][1]] == 1 && res[tmp[i][2]] == 1) res[tmp[i][0]] = 0;
		}
		for(i=1;i<=a+b+c;i++){
			cout<<res[i]<<endl;
		}
	}
	
	return 0;
}
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

struct Data
{
	int p[3], r;
};

int main()
{
	int a, b, c;
	while(scanf("%d%d%d", &a, &b, &c), a){
		int n;
		scanf("%d", &n);
		vector<int> state(a+b+c, 2);
		vector<Data> d(n);
		
		for(int i=0; i<n; ++i){
			for(int j=0; j<3; ++j){
				scanf("%d", &d[i].p[j]);
				d[i].p[j]--;
			}
			scanf("%d", &d[i].r);
			
			if(d[i].r == 1){
				for(int j=0; j<3; ++j)
					state[d[i].p[j]] = 1;
			}
		}
		
		for(int i=0; i<n; ++i){
			if(d[i].r == 0){
				for(int j=0; j<3; ++j){
					if(state[d[i].p[j]]==1 && state[d[i].p[(j+1)%3]]==1 && state[d[i].p[(j+2)%3]]==2){
						state[d[i].p[(j+2)%3]] = 0;
						break;
					}
				}
			}
		}
		
		for(int i=0; i<a+b+c; ++i)
			printf("%d\n", state[i]);
	}
	
	return 0;
}