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

int main(){
  int a, b, c, N;
  int flag[3][1000], judge[1000], info[301];

  while(cin >> a >> b >> c , a+b+c){
    fill_n(info,301,2);
    cin >> N;
    for(int i = 0 ; i < N ; i++ ){
      for(int j = 0 ; j < 3 ; j++) cin >> flag[j][i];
      cin >> judge[i];
      if(judge[i] == 1) for(int j = 0 ; j < 3 ; j++ ) info[flag[j][i]] = 1;
    }
    for(int i = 0 ; i < N ; i++ ){
      if(!judge[i]){
        for(int j = 0 ; j < 3 ; j++){
          if(info[flag[j][i]] == 1 && info[flag[(j+1)%3][i]] == 1){
            info[flag[(j+2)%3][i]] = 0;
          }
        }
      }
    }
    for(int i = 1 ; i <= a+b+c ; i++ ) cout << info[i] << endl;
  }
}
#include<iostream>
using namespace std;

int main(){

  int a[1111], b[1111], c[1111], d[1111], p[333], n;
  
  while(cin >> a[0] >> b[0] >> c[0], *a+=*b+*c){
    for(int i=332;i;) p[i--] = 2;
    
    cin >> n;
    for(int i=0;i++<n;) cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    for(int i=0;i++<n;){
      for(int j=0;j++<n;){
	if(d[j]) p[a[j]] = p[b[j]] = p[c[j]] = 1;
	else{
	  if(p[a[j]] == 1 && p[b[j]] == 1) p[c[j]] = 0;
	  if(p[a[j]] == 1 && p[c[j]] == 1) p[b[j]] = 0;
	  if(p[b[j]] == 1 && p[c[j]] == 1) p[a[j]] = 0;
	}
      }
    }
    for(int i=0;i<*a;) cout << p[++i] << endl;
  }
  
}