#include <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-6;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;


class Point{
public:
  double x, y, z;

  Point(double x = 0.0, double y = 0.0, double z = 0.0) : x(x), y(y), z(z){}

  Point& operator += (const Point& p){ x += p.x; y += p.y; z += p.z; return *this;}
  Point operator + (const Point& p) const{ Point q = *this;return q += p;}
  Point& operator -= (const Point& p){ x -= p.x; y -= p.y; z -= p.z; return *this;}
  Point operator - (const Point& p) const{ Point q = *this; return q -= p;}
  Point& operator *= (double a){ x *= a; y *= a; z *= a; return *this;}
  Point operator * (double a) const{ Point q = *this; return q *= a;}
  Point& operator /= (double a){ x /= a; y /= a; z /= a; return *this;}
  Point operator / (double a) const{ Point q = *this; return q /= a;}

  double abs() const { return sqrt(norm()); }
  double norm() const { return x*x + y*y + z*z; }
  Point& normalize(){ return *this /= abs(); }
  
  //EPSテ」ツ?ッテ・ツ債?・ツ按?・ツーツ湘」ツ?陛」ツ?ェテ・ツ?、
  bool operator == (const Point &p) const {
	return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS && fabs(z - p.z) < EPS;
  }
  friend ostream& operator <<(ostream& os, const Point& p);
};
ostream& operator <<(ostream& os, const Point& p){
  return os << fixed << setprecision(3) << p.x << " " << p.y << " "<< p.z;
}
class Circle{
public:
	Point c;
	double r;
};
class Segment{
public:
  Point p1, p2;
  Segment(){}
  Segment(const Point& p1_, const Point& p2_)
	: p1(p1_), p2(p2_)
  {}
};
//テァツつケテ」ツつ津ァツキツ堙」ツ?ィテ」ツ?療」ツ?ヲテヲツ可アテ」ツ??
typedef Point Vector;
//テァツキツ堙・ツ按?」ツつ津ァツ崢エテァツキツ堙」ツ?ィテ」ツ?療」ツ?ヲテヲツ可アテ」ツ??
typedef Segment Line;
double dot(Vector a, Vector b){
  return a.x*b.x + a.y*b.y + a.z * b.z;
}

Point project(const Line& s, const Point& p){
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}

bool getCrossPoints(const Circle& c, const Line& l, pair<Point, Point>& res){
	Vector pr = project(l, c.c);
	if((pr-c.c).norm() > c.r * c.r + EPS)
	  return false;
	Vector e = (l.p2 - l.p1) / (l.p2 - l.p1).abs();
	if(dot(e, pr - l.p1) < EPS) return false;

	double base = sqrt(c.r*c.r - (pr - c.c).norm());
	res = make_pair(pr + e * base, pr - e*base);
	return true;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  while(cin>>N,N){
	Line ray;
	ray.p1 = Point(0,0,0);
	cin >> ray.p2.x >> ray.p2.y >> ray.p2.z;

	vector<Circle> cs(N);
	REP(i,N)
	  cin >> cs[i].c.x >> cs[i].c.y >> cs[i].c.z >> cs[i].r;

	Point ans;
	while(true){
	  int mi = -1;
	  double md = 1e15;
	  REP(i,N){
		pair<Point,Point> res;
		if(getCrossPoints(cs[i], ray, res)){
		  double d = min((res.FF-ray.p1).norm(), (res.SS-ray.p1).norm());
		  if(d < md){
			md = d;
			mi = i;
		  }
		}
	  }

	  if(mi < 0) break;
	  pair<Point,Point> res;
	  getCrossPoints(cs[mi], ray, res);
	  if((res.FF-ray.p1).norm() < (res.SS-ray.p1).norm())
		ans = res.FF;
	  else
		ans = res.SS;
	  
	  Vector dr = ans - ray.p1;
	  Vector n = (ans - cs[mi].c).normalize();
	  n *= abs(dot(n, dr));
	  dr += n;
	  
	  ray.p2 = dr * 2. + ray.p1;
	  ray.p1 = ans;
	}

	cout << ans << endl;
  }

  return 0;
}