#include<iostream>
using namespace std;
int main(void)
{
  int ok[512];
  int a, b, c, n, i[1024], j[1024], k[1024], r[1024];
  while(cin >> a >> b >> c, (a + b + c)){
    cin >> n;
    for(int s = 0;s < 512; s++) ok[s] = 2;
    for(int s = 0;s < n; s++){
      cin >> i[s] >> j[s] >> k[s] >> r[s];
      if(r[s] == 1)
	ok[i[s]] = ok[j[s]] = ok[k[s]] = 1;
    }
    for(int s = 0;s < n; s++){
      if(ok[i[s]] == 2 && ok[j[s]] == 1 && ok[k[s]] == 1)
	ok[i[s]] = 0;
      if(ok[i[s]] == 1 && ok[j[s]] == 2 && ok[k[s]] == 1)
	ok[j[s]] = 0;
      if(ok[i[s]] == 1 && ok[j[s]] == 1 && ok[k[s]] == 2)
	ok[k[s]] = 0;
    }
    for(int s = 1;s <= a + b + c; s++) cout << ok[s] << endl;	
  }
}
