#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
using namespace std;
typedef long long ll;

struct Test
{
	int a, b, c, r;
};

int A, B, C, N;

int main()
{
	while(cin>>A>>B>>C && (A || B || C) ){
		cin>>N;
		
		vector<int> res;
		vector<Test> test;

		for(int i = 0; i <= A+B+C; i++) res.push_back(2);

		for(int i = 0; i < N; i++){
			Test t;
			cin>>t.a>>t.b>>t.c>>t.r;
			if(t.r){
				res[t.a] = 1; res[t.b] = 1; res[t.c] = 1;
			}else{
				test.push_back(t);
			}
		}
		for(int i = 0; i < test.size(); i++){
			if(res[test[i].a] == 1 && res[test[i].b] == 1) res[test[i].c] = 0;
			if(res[test[i].b] == 1 && res[test[i].c] == 1) res[test[i].a] = 0;
			if(res[test[i].c] == 1 && res[test[i].a] == 1) res[test[i].b] = 0;
		}
		for(int i = 1; i <= A+B+C; i++) cout<<res[i]<<endl;
	}
}