loop do
  a,b,c = gets.chomp.split.map(&:to_i)
  break if (a|b|c) == 0
  parts = Array.new(a + b + c + 1, 2)

  n = gets.chomp.to_i
  fail_list = []
  n.times do
    i,j,k,r = gets.chomp.split.map(&:to_i)
    if r == 1
      parts[i] = 1
      parts[j] = 1
      parts[k] = 1
    else
      fail_list << [i,j,k]
    end
  end

  fail_list.each do |comb|
    fails = []
    comb.each do |p|
      unless parts[p] == 1
        fails << p
      end
    end

    unless fails.size == 1
      next
    end

    parts[fails[0]] = 0
  end

  (1..parts.size-1).each do |i|
    puts parts[i]
  end
end