#include <iostream>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	while (true) {
		int a, b, c, n;
		int ans[300], d[1000][4];
		cin >> a >> b >> c;
		if (!a && !b && !c) break;
		cin >> n;

		fill(ans, ans + a + b + c, 2);

		REP(i, n) {
			REP(j, 4) cin >> d[i][j];
			REP(j, 3) d[i][j]--;
			if (d[i][3] == 1) REP(j, 3) ans[d[i][j]] = 1;
		}
		REP(i, n) {
			if (d[i][3] == 0) {
				REP(j, 3) if (ans[d[i][(j+1)%3]] == 1 && ans[d[i][(j+2)%3]] == 1)
					ans[d[i][j]] = 0;
			}
		}

		REP(i, a + b + c) cout << ans[i] << endl;
	}
	return 0;
}