loop do
    a, b, c = gets.split.map(&:to_i)
    break if a == 0
    n = gets.to_i

    tests = (1..n).map { gets.split.map(&:to_i) }
    state = {}

    loop do
        changed = false
        test_num = tests.size
        retests = []
        tests.each do |i, j, k, c|
            if c == 1
                state[i] = state[j] = state[k] = 1
            elsif state[i] == 1 && state[j] == 1
                state[k] = 0
            elsif state[j] == 1 && state[k] == 1
                state[i] = 0
            elsif state[k] == 1 && state[i] == 1
                state[j] = 0
            elsif [i, j, k].any?{|x| state[x] == 0}
                #do nothing
            else
                retests << [i, j, k, c]
            end
        end
        break if retests.size == test_num
        tests = retests
    end

    (1..a+b+c).each do |i|
        puts state[i] || 2
    end
end