### main

loop do
  a, b, c = gets.strip.split(' ').map{|s| s.to_i}
  break if (a | b | c) == 0

  n = gets.strip.to_i

  abc = a + b + c
  qcs = abc.times.map{2}

  fails = []

  n.times do
    i, j, k, r = gets.strip.split(' ').map{|s| s.to_i}
    i -= 1
    j -= 1
    k -= 1

    if r == 1
      qcs[i] = qcs[j] = qcs[k] = 1
    else
      fails << [i, j, k]
    end
  end

  for fail in fails
    i, j, k = fail

    if qcs[i] == 1 && qcs[j] == 1
      qcs[k] = 0
    elsif qcs[j] == 1 && qcs[k] == 1
      qcs[i] = 0
    elsif qcs[k] == 1 && qcs[i] == 1
      qcs[j] = 0
    end
  end

  for qc in qcs
    puts qc
  end
end