#include<iostream>
#include<string>
#include<algorithm>
#define int long long
using namespace std;
int ok[213456];
int i[213456], j[213456], k[213456], r[213456];
signed main() {
	for (int un = 0; un < 100; un++) {
		for (int in = 0; in < 213456; in++) {
			ok[in] = 0; i[in] = 0; j[in] = 0; k[in] = 0; r[in] = 0;
		}
		int n, a, b, c, I, J, K, R; cin >> a >> b >> c;
		if (a == 0 && b == 0 && c == 0) { return 0; }
		cin >> n;
		for (int h = 0; h < n; h++) {
			for (int z = 0; z < n; z++) {
				if (h == 0) {
					cin >> I >> J >> K >> R;
					i[z] = I; j[z] = J; k[z] = K; r[z] = R;
				}
				if (r[z] == 1) {
					ok[i[z]] = 1; ok[j[z]] = 1; ok[k[z]] = 1;
				}
				else {
					if (ok[i[z]] == 1 && ok[j[z]] == 1) { ok[k[z]] = 2; }
					if (ok[i[z]] == 1 && ok[k[z]] == 1) { ok[j[z]] = 2; }
					if (ok[j[z]] == 1 && ok[k[z]] == 1) { ok[i[z]] = 2; }
				}
			}
		}
		for (int h = 1; h <= a + b + c; h++) {
			cout << 2 - ok[h] << endl;
		}
	}
	return 0;
}

