#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a,b,c;
	while(cin>>a>>b>>c,a+b+c){
		vector<int>in(a+b+c+1,2);
		int n;
		cin>>n;
		vector<vector<int> >tmp(n,vector<int>(4));
		rep(i,n)rep(j,4)cin>>tmp[i][j];
		rep(i,n)if(tmp[i][3]==1){
			in[tmp[i][0]]=1;
			in[tmp[i][1]]=1;
			in[tmp[i][2]]=1;
		}
		rep(i,n){
			int co=0;
			rep(j,3)if(in[tmp[i][j]]!=1)co++;
			if(co==1){
				rep(j,3)if(in[tmp[i][j]]==2)in[tmp[i][j]]=0;
			}
		}
		loop(i,1,a+b+c+1)cout<<in[i]<<endl;
	}
}
#include <iostream>
using namespace std;

int main() {
	int a,b,c,n,buhin[300],kensa[1000][4];
	while(1){
	for(int i = 0;i < 300;i++) buhin[i] = 2; 
	cin >> a >> b >> c >> n;
	if(a == 0 && b == 0 && c == 0) break;
	for(int i = 0;i < n;i++){
		cin >> kensa[i][0] >> kensa[i][1] >> kensa[i][2] >> kensa[i][3];
		if(kensa[i][3]){
			buhin[kensa[i][0] - 1] = 1;
			buhin[kensa[i][1] - 1] = 1;
			buhin[kensa[i][2] - 1] = 1;
		}
	}
	for(int i = 0;i < n;i++){
		if(!kensa[i][3]){
			if(buhin[kensa[i][0] - 1] == 1 && buhin[kensa[i][1] - 1] == 1) buhin[kensa[i][2] - 1] = 0;
			if(buhin[kensa[i][0] - 1] == 1 && buhin[kensa[i][2] - 1] == 1) buhin[kensa[i][1] - 1] = 0;
			if(buhin[kensa[i][2] - 1] == 1 && buhin[kensa[i][1] - 1] == 1) buhin[kensa[i][0] - 1] = 0;
		}
	}
	for(int i = 0;i < a + b + c;i++) cout << buhin[i] << endl;
	}
	return 0;
}