#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <cstring>

#define NOT_DEFINED 2
#define NORMAL 1
#define IRREGULAR 0

using namespace std;

typedef struct {
    int battery;
    int motor;
    int cable;
    bool hasSucceeded;
} Query;

struct IsSuccess {
    bool operator()(Query &a, Query &b) const {
        return (a.hasSucceeded < b.hasSucceeded);
    }
};


char parts[300];

int main() {
    while (1) {
        int i, a, b, c;
        int N;
        priority_queue<Query, vector<Query>, IsSuccess> queries;

        scanf("%d %d %d", &a, &b, &c);
        if (a == 0 && b == 0 && c ==0) {
            return 0;
        }

        scanf("%d", &N);
        for (i=0;i<N;i++) {
            int i, j, k ,r;
            Query query;

            scanf("%d %d %d %d", &i, &j, &k, &r);
            query.battery = i-1;
            query.motor = j-1;
            query.cable = k-1;
            query.hasSucceeded = r;

            queries.push(query);
        }

        memset(parts, NOT_DEFINED, 300);

        while (!queries.empty()) {
            int i, j, k, r;
            Query query = queries.top();

            i = query.battery;
            j = query.motor;
            k = query.cable;
            r = query.hasSucceeded;

            if (r) {
                parts[i] = NORMAL;
                parts[j] = NORMAL;
                parts[k] = NORMAL;
            } else {
                if (parts[i] == NORMAL && parts[j] == NORMAL) {
                    parts[k] = IRREGULAR;
                }

                if (parts[j] == NORMAL && parts[k] == NORMAL) {
                    parts[i] = IRREGULAR;
                }

                if (parts[k] == NORMAL && parts[i] == NORMAL) {
                    parts[j] = IRREGULAR;
                }
            }

            queries.pop();
        }

        for (i=0;i<a+b+c;i++) {
            printf("%d\n", parts[i]);
        }
    }
}
#include <cstdio>
#include <algorithm>
using namespace std;

int a, b, c, N, i[1000], j[1000], k[1000], r[1000], h[301];

int main(){
    while(scanf("%d%d%d", &a, &b, &c), a+b+c){
        scanf("%d", &N);
        for(int x = 0; x < N; x++){
            scanf("%d%d%d%d", i+x, j+x, k+x, r+x);
        }
        fill(h, h+301, 2);
        for(int x = 0; x < N; x++){
            if(r[x] == 1){
                h[i[x]] = h[j[x]] = h[k[x]] = 1;
            }
        }
        for(int x = 0; x < N; x++){
            if(r[x]) continue;
            if(h[i[x]]%2 + h[j[x]]%2 + h[k[x]]%2 == 2){
                if(h[i[x]]/2){
                    h[i[x]] = 0;
                }
                if(h[j[x]]/2){
                    h[j[x]] = 0;
                }
                if(h[k[x]]/2){
                    h[k[x]] = 0;
                }
            }
        }
        for(int x = 1; x <= a+b+c; x++){
            printf("%d\n", h[x]);
        }
    }
    return 0;
}