loop do
  a,b,c = gets.split.map(&:to_i)
  break if (a|b|c)==0
  n =gets.to_i
  items = Array.new(a+b+c+1,2)
  sets = Array.new
  n.times do
    i,j,k,r = gets.split.map(&:to_i)
    set=[i,j,k,r]
    if r==1
      sets.unshift(set)
    else
      sets << set
    end
  end
  sets.each do |ary|
    if ary[3]==1
      (0..2).each do|i|
        items[ary[i]]=1
      end
    else
      result = [items[ary[0]],items[ary[1]],items[ary[2]]]
      if result.count(1)==2 && result.count(2)==1
        items[ary[result.index(2)]]=0

      end
    end
  end
  items.delete_at(0)
  puts items
end