#include <iostream>
#include <cctype>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <complex>
#include <cstring>
#include <set>
using namespace std;
#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,a) loop(i,0,a)

int input[1111][3], res[1111];

int main(){
    int a,b,c;
    while(cin>>a>>b>>c && a){
        int n; cin>>n;
        rep(i,n){
            rep(j,3)cin >> input[i][j];
            cin>>res[i];
        }

        bool ok[1111]={}, bad[1111]={};
        rep(k,2){
            rep(i,n){
                int a=0,b=0;
                int x,y,z;
                tie(x,y,z)=tie(input[i][0],input[i][1],input[i][2]);
                for(int j : {x,y,z}){
                    if(ok[j])a++;
                    if(bad[j])b++;
                }
                if(res[i]){
                    if(a!=3){
                        ok[x]=ok[y]=ok[z]=true;
                    }
                }else{
                    if(a==2 && b!=1){
                        for(int j : {x,y,z}){
                            if(!ok[j])bad[j]=true;
                        }
                    }
                }
            }
        }
        for(int i=1;i<=a+b+c;i++){
            if(ok[i] && !bad[i])cout<<1;
            else if(!ok[i] && bad[i])cout<<0;
            else cout<<2;
            cout<<endl;
        }
    }
}
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int a, b, c, n;
        cin >> a >> b >> c >> n;
        if(a == 0)
            return 0;

        vector<vector<int> > check(n, vector<int>(4));
        for(int i=0; i<n; ++i){
            for(int j=0; j<4; ++j)
                cin >> check[i][j];
        }

        vector<int> quality(a+b+c+1, 2);
        for(int i=0; i<n; ++i){
            if(check[i][3] == 1){
                quality[check[i][0]] = 1;
                quality[check[i][1]] = 1;
                quality[check[i][2]] = 1;
            }
        }
        for(int i=0; i<n; ++i){
            if(check[i][3] == 0){
                if(quality[check[i][0]] == 1 && quality[check[i][1]] == 1)
                    quality[check[i][2]] = 0;
                if(quality[check[i][1]] == 1 && quality[check[i][2]] == 1)
                    quality[check[i][0]] = 0;
                if(quality[check[i][2]] == 1 && quality[check[i][0]] == 1)
                    quality[check[i][1]] = 0;
            }
        }

        for(int i=1; i<=a+b+c; ++i)
            cout << quality[i] << endl;
    }
}