#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[1000][4];
int b[302];
int main(){
	int x, y, z, n, t;
	while(1){
		scanf("%d%d%d", &x, &y, &z);
		if(!x&&!y&&!z)break;
		scanf("%d", &n);
		fill(b, b+302, 2);
		for(int i = 0;i < n;i++){
			scanf("%d%d%d%d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]);
			if(a[i][3])b[a[i][0]] = b[a[i][1]] = b[a[i][2]] = 1;
		}
		for(int i = 0;i < n;i++){
			t = 0;
			if(a[i][3] == 0){
				rep(j,3)if(b[a[i][j]] == 1)t++;
				if(t == 2)rep(j,3)if(b[a[i][j]]==2)b[a[i][j]] = 0;
			}
		}
		rrep(i,x+y+z)printf("%d\n", b[i]);
	}
	return 0;
}