#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>

using namespace std;

int a, b, c, N;
int Ans[1000];
int tmps[100][100][100];
int main() {
	while (true) {
		cin >> a >> b >> c;
		if (a == 0) break;
		cin >> N;

		for (int i = 0; i < (a + b + c); i++) {
			Ans[i] = 2;
		}
		for (int i = 0; i < a; i++)
			for (int j = 0; j < b; j++)
				for (int k = 0; k < c; k++)
					tmps[i][j][k] = -1;

		for (int i = 0; i < N; i++) {
			int ti, tj, tk, tr;
			cin >> ti >> tj >> tk >> tr;
			tj -= a;
			tk -= (a + b);
			tmps[ti - 1][tj - 1][tk - 1] = tr;
		}

		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				for (int k = 0; k < c; k++) {
					if (tmps[i][j][k] == 1) {
						Ans[i] = 1;
						Ans[j + a] = 1;
						Ans[k + a + b] = 1;
					}
				}
			}
		}

		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				for (int k = 0; k < c; k++) {
					if (tmps[i][j][k] == 0) {
						if (Ans[i] == 1 && Ans[a + j] == 1) {
							Ans[a + b + k] = 0;
						}
						else if (Ans[a + j] == 1 && Ans[a + b + k] == 1) {
							Ans[i] = 0;
						}
						else if (Ans[i] == 1 && Ans[a + b + k] == 1) {
							Ans[a + j] = 0;
						}
					}
				}
			}
		}

		for (int i = 0; i < a + b + c; i++) {
			cout << Ans[i] << endl;
		}

	}

	return 0;
}

/*
int main() {
	int N;
	string name;
	int ans = 0;

	cin >> N >> name;

		string word;
	for (int i = 0; i < N; i++) {
		cin >> word;

		vector<int> first, second;
		for (int j = 0; j < word.size(); j++) {
			if (name[0] == word[j]) {
				first.push_back(j);
			}
		}
		for (int j = 0; j < word.size(); j++) {
			if (name[1] == word[j]) {
				second.push_back(j);
			}
		}

		bool judge = true;
		for (int j = 0; j < first.size() && judge == true; j++) {
			for (int k = 0; k < second.size() && judge == true; k++) {
				if (first[j] < second[k]) {
					int tmp = first[j];
					for (int l = 0; l < name.size() && tmp < word.size(); l++) {
						if (word[tmp] != name[l]) {
							break;
						}
						else if (l == name.size() - 1) {
							ans++;
							judge = false;
						}
						tmp += second[k] - first[j];
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}
*/
/*
int main() {
	int N, K;
	cin >> N >> K;

	for (int i = 0; i < K; i++) {
		int a, b;
		cin >> a >> b;

		if (a > N / 2) {
			a = N - a + 1;
		}
		if (b > N / 2) {
			b = N - b + 1;
		}

		int tmp = min(a, b);
		
		tmp = tmp % 3;
		if (tmp == 0) tmp = 3;

		cout << tmp << endl;
	}

	return 0;
}
*/

/*
//パーティー
int main() {
	int N, M;
	cin >> N >> M;
	bool Friends[500][500] = {};
	bool already[500] = {};
	already[0] = true;

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		Friends[a][b] = true;
		Friends[b][a] = true;
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (Friends[0][i] == true) {
			if (already[i] == false) {
				ans++;
				already[i] = true;
			}
			for (int j = 0; j < N; j++) {
				if (Friends[i][j] == true && already[j] == false) {
					already[j] = true;
					ans++;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}
*/

/*
//カードゲーム
int main() {
	int N;
	cin >> N;
	int TaroSize = N;
	int HanaSize = N;

	int Taro[210];
	for (int i = 1; i <= 2 * N; i++) {
		Taro[i] = -1;
	}

	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		Taro[tmp] = 1;
	}

	bool TaroTurn = true;
	int Now = 0;
	while (TaroSize != 0 && HanaSize != 0) {
		if (TaroTurn) {
			for (int i = Now + 1; i <= 2 * N; i++) {
				if (Taro[i] == 1) {
					Now = i;
					Taro[i] = 0;
					TaroSize--;
					TaroTurn = false;
					if (Now == 2 * N) {
						Now = 0;
						TaroTurn = true;
					}
					break;
				}
				else if (i >= 2 * N - 1) {
					Now = 0;
					TaroTurn = false;
				}
			}
		}
		else {
			for (int i = Now + 1; i <= 2 * N; i++) {
				if (Taro[i] == -1) {
					Now = i;
					Taro[i] = 0;
					HanaSize--;
					TaroTurn = true;
					if (Now == 2 * N) {
						Now = 0;
						TaroTurn = false;
					}
					break;
				}
				if (i >= 2 * N) {
					Now = 0;
					TaroTurn = true;
				}
			}
		}
	}

	cout << HanaSize << endl;
	cout << TaroSize << endl;


	return 0;
}
*/


Measured memory_bytes: 6904