#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	while(true){
		int a, b, c, N, i, j, t1, t2, t3, r;
		scanf("%d %d %d", &a, &b, &c);
		if(a == 0 && b == 0 && c == 0) return 0;
		scanf("%d", &N);

		vector< vector<int> > results;
		vector<int> ans(a+b+c+1, 2);

		for(i = 0;i < N;++i){
			vector<int> re;
			scanf("%d %d %d %d", &t1, &t2, &t3, &r);
			re.push_back(t1);re.push_back(t2);re.push_back(t3);re.push_back(r);
			results.push_back(re);

			if(r == 1){
				ans[t1] = 1;ans[t2] = 1;ans[t3] = 1;
			}
		}

		for(i = 0;i < N;++i){
			vector<int> re = results[i];
			if(re[3] == 0){
				if(ans[re[0]] == 1 && ans[re[1]] == 1){
					ans[re[2]] = 0;
				}else if(ans[re[1]] == 1 && ans[re[2]] == 1){
					ans[re[0]] = 0;
				}else if(ans[re[2]] == 1 && ans[re[0]] == 1){
					ans[re[1]] = 0;
				}
			}	
		}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int main() {
    int n;
    cin >> n;
    int a = 0, out = 0;
    int base[4] = {0};
    string s;
    while (cin >> s) {
        if (s == "HIT") {
            for (int i = 2; i >= 0; i--) {
                if (base[i]) base[i+1] = 1, base[i] = 0;
            }
            base[0] = 1;
            if (base[3]) {
                a++;
                base[3] = 0;
            }
        }else if (s == "HOMERUN") {
            REP(i,3) a += base[i];
            a++;
            REP(i,3) base[i] = 0;
        }else {
            out++;
        }
        if (out == 3) {
            cout << a << endl;
            out = 0;
            a = 0;
            REP(i,4) base[i] = 0;
        }
    }
}