#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    for(;;){
        int ans[10024] = {0};
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        if(a == 0 && b == 0 && c == 0)break;

        for(int i = 1;i < 1024; i++)ans[i] = 2;

        int n;
        scanf("%d",&n);

        int x[1002],y[1002],z[1002],r[1002];//r check
        for(int i = 0;i < n; i++){
            scanf("%d%d%d%d",&x[i],&y[i],&z[i],&r[i]);
            if(r[i] == 1){
                ans[x[i]] = 1;
                ans[y[i]] = 1;
                ans[z[i]] = 1;
                }
        }

        for(int i = 0;i < n; i++){
            if(r[i] == 0){
                if(ans[x[i]] == 1 && ans[y[i]] == 1 && ans[z[i]] != 1)ans[z[i]] = 0;
                else if(ans[x[i]] == 1 && ans[y[i]] != 1 && ans[z[i]] == 1)ans[y[i]] = 0;
                else if(ans[x[i]] != 1 && ans[y[i]] == 1 && ans[z[i]] == 1)ans[x[i]] = 0;
            }
        }

        for(int i = 1;i < a+b+c+1; i++)printf("%d\n",ans[i]);
    }
    return 0;
}