loop do
  a, b, c = gets.split.map(&:to_i)
  break if a == 0
  n = gets.to_i
  r = []
  resa = []
  resb = []
  resc = []
  n.times do
    x = gets.split.map(&:to_i)
    u = [x[0] - 1, x[1] - a - 1, x[2] - a - b - 1, x[3]]
    if u[3] == 1
      resa[u[0]] = 1
      resb[u[1]] = 1
      resc[u[2]] = 1
    else
      r << u[0..2]
    end
  end

  r.each do |(ra, rb, rc)|
    if resa[ra] == 1 && resb[rb] == 1 && resc[rc] != 1 # C ?????????
      resc[rc] = 0
      next
    end
    if resa[ra] != 1 && resb[rb] == 1 && resc[rc] == 1 # A ?????????
      resa[ra] = 0
      next
    end
    if resa[ra] == 1 && resb[rb] != 1 && resc[rc] == 1 # B ?????????
      resb[rb] = 0
      next
    end

    if resa[ra] == 1
      resb[rb] ||= 2
      resc[rc] ||= 2
    end
    if resb[rb] == 1
      resa[ra] ||= 2
      resc[rc] ||= 2
    end
    if resc[rc] == 1
      resa[ra] ||= 2
      resb[rb] ||= 2
    end
  end

  resa.each { |v| puts v }
  resb.each { |v| puts v }
  resc.each { |v| puts v }

end