#include<cstdio>
 
int main()
{
while(true) {

int a, b, c, n;
int test[3000], r[1000];
int ans[1000];
scanf("%d%d%d", &a, &b, &c);
if(a == 0)
break;
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d%d%d%d", test + i * 3, test + i * 3 + 1, test + i * 3 + 2, r + i);
test[i * 3] -= 1, test[i * 3 + 1] -= 1, test[i * 3 + 2] -= 1;
}

for(int i = 0; i < a + b + c; ++i)
ans[i] = 2;
for(int i = 0; i < n; ++i) {
if(r[i] != 1)
continue;
for(int j = i * 3; j < i * 3 + 3; ++j)
ans[test[j]] = 1;
}
for(int i = 0; i < n; ++i) {
if(r[i] != 0)
continue;
int correct = 0;
for(int j = i * 3; j < i * 3 + 3; ++j)
correct += (ans[test[j]] == 1);
if(correct != 2)
continue;
for(int j = i * 3; j < i * 3 + 3; ++j) {
if(ans[test[j]] != 1)
ans[test[j]] = 0;
}
}
for(int i = 0; i < a + b + c; ++i)
printf("%d\n", ans[i]);
}
return 0;
}

#include<iostream>
using namespace std;

struct Test{
  int A[3];
  bool R;
};

Test tests[1000];
int info[301], M[3], N;

int main()
{
  while(true)
  {
    for(int i = 0; i <= 300; i++)
      info[i] = 2;
  
    cin >> M[0] >> M[1] >> M[2];
    if(!(M[0] || M[1] || M[2]))
      break;
    cin >> N;
    for(int i = 1; i <= N; i++)
     cin >> tests[i].A[0] >> tests[i].A[1] >> tests[i].A[2] >> tests[i].R;

    bool b = true;
    while(b)
    {
      b = false;
      for(int i = 1; i <= N; i++)
      {
        if(tests[i].R)
        {
          for(int j = 0; j < 3; j++)
          {
            if(info[tests[i].A[j]] != 1)
            {
              info[tests[i].A[j]] = 1;
              b = true;
            }
          }
        }
        else
        {
          int tmp = 0;
          bool f = false;
          for(int j = 0; j < 3; j++)
          {
            tmp += info[tests[i].A[j]] == 1;
          }
          if(tmp == 2)
          {
            for(int j = 0; j < 3; j++)
            {
              if(info[tests[i].A[j]] == 2)
              {
                info[tests[i].A[j]] = 0;
                b = true;
              }
            }
          }
        }
      }
    }
    for(int i = 1; i <= M[0] + M[1] + M[2]; i++)
    {
       cout << info[i] << endl;
    }
  }
}