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

int main(){
	int n,a,b,c,r;
	
	while(cin >> a >> b >> c && a || b || c){
		vector<int>part(a+b+c+1,0);
		int d[1000][4];
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> d[i][0] >> d[i][1] >> d[i][2] >> d[i][3];
		}
		for(int k=0;k<n;k++){
			for(int i=0;i<n;i++){
				if(d[i][3]){
					part[ d[i][0] ] = part[ d[i][1] ] = part[ d[i][2] ] = 1;
				}else{
					//cout <<d[i][0] << " " << d[i][1] << " " << d[i][2] << endl;	
					if(	 part[ d[i][1] ]>0 && part[ d[i][2] ]>0)part[ d[i][0] ]=-1;
					else if(part[ d[i][0] ]>0 && part[ d[i][2] ]>0)part[ d[i][1] ]=-1;
					else if(part[ d[i][0] ]>0 && part[ d[i][1] ]>0)part[ d[i][2] ]=-1;
				}
			}
		}
				
		for(int i=1;i<part.size();i++){
			if(part[i]==0)cout << 2;
			if(part[i]==-1)cout << 0;
			if(part[i]==1)cout << 1;
			cout << endl;
		}
	}
}