def main(input = STDIN)
  a, b, c = input.gets.split(" ").map(&:to_i)
  array = Array.new(a + b + c + 1)
  test = []
  input.gets.to_i.times do
    test << input.gets.split(" ").map(&:to_i)
  end
  test.sort_by!{|i|-i[3]}
  #p test
  test.each do |arg|
    if arg[3] == 1
      array[arg[0]], array[arg[1]], array[arg[2]] = true, true, true
      #p [arg, array]
    elsif [array[arg[0]], array[arg[1]], array[arg[2]]].select{|i|i}.size == 2
      array[arg.find{|i|array[i].nil?}] = false
      #p [arg, [array[arg[0]], array[arg[1]], array[arg[2]]]]
    end
  end
  puts array[1..-1].map{|i|
    if i
      1
    elsif i.nil?
      2
    else
      0
    end
  }
end
main