while true
  a, b, c = gets.split.map(&:to_i)
  break if a == 0 && b == 0 && c == 0

  res = Array.new(a+b+c+1, 2)
  tasks = []
  gets.to_i.times do
    i, j, k, l = gets.split.map(&:to_i)
    if l == 1
      res[i], res[j], res[k] = 1, 1, 1
    else
      tasks << [i, j, k]
    end
  end

  tasks.each do |task|
    corrects = []
    task.each{ |n| corrects << n if res[n] == 1 }
    if corrects.size == 2
      incorrect = (task - corrects).first
      res[incorrect] = 0
    end
  end

  res.shift
  puts res
end