#include <vector>
#include <iostream>
using namespace std;
int A, B, C, Q; vector<int> a, b, c, t, x;
int main() {
	while (cin >> A >> B >> C, A) {
		cin >> Q;
		a.resize(Q);
		b.resize(Q);
		c.resize(Q);
		t.resize(Q);
		for (int i = 0; i < Q; i++) {
			cin >> a[i] >> b[i] >> c[i] >> t[i];
			a[i]--, b[i]--, c[i]--;
		}
		x = vector<int>(A + B + C, 2);
		for (int i = 0; i < Q; i++) {
			if(t[i] == 1) {
				x[a[i]] = 1;
				x[b[i]] = 1;
				x[c[i]] = 1;
			}
		}
		for (int i = 0; i < Q; i++) {
			if (t[i] == 0) {
				int ta = (x[a[i]] == 1 ? 1 : 0);
				int tb = (x[b[i]] == 1 ? 1 : 0);
				int tc = (x[c[i]] == 1 ? 1 : 0);
				if (ta + tb + tc == 2) {
					if (ta == 0) x[a[i]] = 0;
					if (tb == 0) x[b[i]] = 0;
					if (tc == 0) x[c[i]] = 0;
				}
			}
		}
		for (int i = 0; i < A + B + C; i++) cout << x[i] << endl;
	}
	return 0;
}