#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a,b,c,n;
	while(cin>>a>>b>>c>>n,a){
		int p[301]={0};
		vector<vector<int> > q;
		rep(i,n){
			vector<int> t(4);
			cin>>t[0]>>t[1]>>t[2]>>t[3];
			if(t[3])p[t[0]]=p[t[1]]=p[t[2]]=1;
			else q.push_back(t);
		}
		rep(i,q.size()){
			int c=0; rep(j,3)c+=p[q[i][j]]==1;
			if(c==2)rep(j,3)if(p[q[i][j]]==0)p[q[i][j]]=2;
		}
		rep(i,a+b+c)cout<<2-p[i+1]<<endl;
	}
	return 0;
}