#include<iostream>

using namespace std;

int main(){
	int a, b, c, n, i, j, s, judge;
	int *damy = 0, *ok = 0, *ng = 0, *que = 0;
	int okcut = 0, ngcut = 0, check[1000][3];

	while(1){
	cin >> a >> b >> c;
	if(a == 0 && b == 0 && c == 0) break;
	s = a+b+c+1;
	que = new int[s];
	damy = new int[s];
	ok = new int[s];
	ng = new int[s];
	cin >> n;

	for(i = 0; i < n; i ++){
		for(j = 0; j < 3; j ++){
			cin >> check[i][j];
		}
		cin >> judge;
		if(judge == 1){
			ok[check[i][0]] = 1;
			ok[check[i][1]] = 1;
			ok[check[i][2]] = 1;
		}
	}
	for(i = 0; i < n; i ++){
		for(j = 0; j < 3; j	++){
			if(ok[check[i][j]] == 1) okcut ++;
			else ngcut = check[i][j];
			if(okcut == 2) ng[ngcut] = 1;
		}
		okcut = 0, ngcut = 0;
	}
	for(i = 1; i < s; i ++){
		if(ok[i] != 1 || ng[i] != 1) que[i] = 1;
	}
	for(i = 1; i < s; i ++){
		if(ok[i] == 1) cout << "1" << endl;
		else if(ng[i] == 1) cout << "0" << endl;
		else if(que[i] == 1) cout << "2" << endl;
	}
	}

	return 0;
}