#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  while(cin>>a>>b>>c,a||b||c) {
    int N; cin >> N;
    int info_[4][N];
    FOR(i,0,N) FOR(j,0,4) cin >> info_[j][i];
    int info[a+b+c+1];
    FOR(i,0,a+b+c+1) info[i] = 2;
    // ???????????????????????¨?????????
    FOR(i,0,N) if(info_[3][i] == 1) FOR(j,0,3) info[info_[j][i]] = 1;

    // ?????????????????¨?????????
    FOR(i,0,N) {
      if(info_[3][i] == 0) {
        int cnt = 0;
        FOR(j,0,3) cnt += info[info_[j][i]];
        if(cnt == 4) {
          FOR(j,0,3) if(info[info_[j][i]] == 2) info[info_[j][i]] = 1000;
        }
      }
    }
    FOR(i,1,a+b+c+1) cout << (info[i] == 1000 ? 0 : info[i]) << '\n';
  }
  return 0;
}
#include<iostream>

using namespace std;

struct ST{
	int a;
	int b;
	int c;

	int an;
};

int reset(int, int */*[100 + 10]*/);

int main()
{
	int ans[1000 + 10];

	ST res[1000 + 10];

	int an, bn, cn, n;

	int ml;

	int ln;

	int i, j;
	int af, bf, cf;

	while (cin >> an >> bn >> cn, an != 0 && bn != 0 && cn != 0)
	{
		cin >> n;

		ln = n;

		ml = an + bn + cn;

		reset(ml, ans);

		for (i = 1; i <= ln; i++)
		{
			cin >> res[i].a >> res[i].b >> res[i].c >> res[i].an;

			if (res[i].an == 1)
			{
				ans[res[i].a] = 1;
				ans[res[i].b] = 1;
				ans[res[i].c] = 1;

				i--;
				ln--;
			}
		}

		for (i = 1; i <= ln; i++)
		{
			af = bf = cf = 0;

			if (ans[res[i].a] == 1) af = 1;
			if (ans[res[i].b] == 1) bf = 1;
			if (ans[res[i].c] == 1) cf = 1;

			if (af + bf + cf == 2)
			{
				if (af == 0)
				{
					ans[res[i].a] = 0;
				}
				if (bf == 0)
				{
					ans[res[i].b] = 0;
				}
				if (cf == 0)
				{
					ans[res[i].c] = 0;
				}
			}
		}

		for (i = 1; i <= ml; i++)
		{
			cout << ans[i] << endl;
		}
	}

	return 0;
}

int reset(int n,int *le)
{
	int i;
	for (i = 0; i < n; i++)
	{
		le[i] = 2;
	}
	return 0;
}