### classes

class Pt3D
  attr_accessor :x, :y, :z

  def initialize() end
  def initialize(x, y, z) @x = x; @y = y; @z = z end

  def ==(pt) @x == pt.x && @y == pt.y && @z == pt.z end
  def +(pt) Pt3D.new(@x + pt.x, @y + pt.y, @z + pt.z) end
  def -(pt) Pt3D.new(@x - pt.x, @y - pt.y, @z - pt.z) end
  def -@() Pt3D.new(-@x, -@y, -@z) end
  def *(t) Pt3D.new(@x * t, @y * t, @z * t) end
  def /(t) Pt3D.new(@x / t, @y / t, @z / t) end
  def dot(v) @x * v.x + @y * v.y + @z * v.z end
  #def cross(v) @x * v.y - @y * v.x end
  def d2() @x * @x + @y * @y + @z * @z end
  def d() Math.sqrt(d2()) end
  def normalize() self / d() end
  def to_s() "(#{@x}, #{@y}, #{@z})" end
  #def hash() @y * W + @x end
end

### main

loop do
  n = gets.to_i
  break if n == 0

  u, v, w = gets.split.map(&:to_f)

  sphs = []
  n.times do
    xi, yi, zi, ri = gets.split.map(&:to_f)
    sphs << [Pt3D.new(xi, yi, zi), ri, ri * ri]
  end
  
  cp = Pt3D.new(0.0, 0.0, 0.0)
  cv = Pt3D.new(u, v, w).normalize
  #p cv.to_s

  loop do
    crpts = []

    for i in (0...n)
      pt, r, r2 = sphs[i]
      t = cv.dot(pt - cp)
      q = (cv * t) + cp
      qd2 = (pt - q).d2
      
      if qd2 <= r2
        s = t - Math.sqrt(r2 - qd2)
        crpts << [s, i] if s >= 0.0
      end
    end
    #p crpts

    break if crpts.empty?

    s, i = crpts.min
    crpt = cv * s + cp
    pt, r, r2 = sphs[i]

    nv = (crpt - pt).normalize

    # R=F+2(&#8722;F.N)N
    rv = cv + nv * (-2 * cv.dot(nv))

    cp = crpt
    cv = rv
  end

  puts [cp.x, cp.y, cp.z].map{|f| "%.4f" % f}.join(' ')
end