#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#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 it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int a,b,c,d;
  while(cin>>a>>b>>c,a||b||c){
    int n;cin>>n;
    int nn=a+b+c;
    vector<int>in(a+b+c+1,2);
    vector<int>tmp;
    rep(i,n){
      cin>>a>>b>>c>>d;
      if(d){
	in[a]=1;in[b]=1;in[c]=1;
      }else{
	tmp.pb(a);
	tmp.pb(b);
	tmp.pb(c);
      }
    }
    rep(i,tmp.size()/3){
      int co=0;
      a=tmp[3*i];b=tmp[3*i+1];c=tmp[3*i+2];
      if(in[a]!=1)co++;
      if(in[b]!=1)co++;
      if(in[c]!=1)co++;
      if(in[a]!=1&&co==1)in[a]=0;
      if(in[b]!=1&&co==1)in[b]=0;
      if(in[c]!=1&&co==1)in[c]=0;
      //cout<<co<<endl;
    }
    loop(i,1,nn+1)cout<<in[i]<<endl;
  }
}