#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int sign(double r){ return (r < -EPS) ? -1 : (r > EPS) ? 1 : 0; }
bool eq(double a, double b){ return abs(b - a) < EPS; }
struct Point{
  double x, y, z;
  Point() {}
  Point(double x, double y, double z) : x(x), y(y), z(z) {}
  Point operator+(const Point& b) const { return Point(x + b.x, y + b.y, z + b.z); }
  Point operator-(const Point& b) const { return Point(x - b.x, y - b.y, z - b.z); }
  Point operator*(const double b) const { return Point(x * b, y * b, z * b); }
  double norm(){ return x * x + y * y + z * z; }
  double abs(){ return sqrt(norm()); }
};
double dot(const Point& a, const Point& b){ return a.x * b.x + a.y * b.y + a.z * b.z; }
struct Line : public vector<Point> {
  Line(const Point& a, const Point& b) {
    push_back(a); push_back(b);
  }
  Point vector() const {
    return back() - front();
  }
};
struct Circle : Point {
  double r;
  Circle(){}
  Circle(Point p, double r) : Point(p), r(r) { }
};
istream& operator>>(istream& is, Point& a){ return is>>a.x>>a.y>>a.z; }
istream& operator>>(istream& is, Circle& a){ return is>>a.x>>a.y>>a.z>>a.r; }
ostream& operator<<(ostream& os, Point& a){ return os<<a.x<<" "<<a.y<<" "<<a.z; }

Point projection(const Line& l, const Point& p){
  double t = dot(p - l[0], l.vector()) / l.vector().norm();
  return l[0] + l.vector() * t;
}
Point reflection(const Line& l, const Point& p){
  return p + (projection(l, p) - p) * 2;
}
vector<Point> crosspointLC(const Line &l, const Circle &c) {
  vector<Point> ret;
  Point center = projection(l, c);
  double d = (center - c).abs();
  double t = sqrt(c.r * c.r - d * d);
  if (isnan(t)) { return ret; }
  Point vect = (l[1] - l[0]);
  vect = vect * (1.0/vect.abs());
  ret.push_back(center - vect * t);
  if (t > EPS) {
    ret.push_back(center + vect * t);
  }
  return ret;
}

int main(){
  int N;
  while(cin >> N && N){
    Point dr; cin >> dr;
    vector<Circle> CV(N);
    REP(i, N){
      cin >> CV[i];
    }
    Line laser(Point(0, 0, 0), dr); // レーザー
    while(true){
      Point ref_point = laser[0] + laser.vector() * 1e8; // 反射点
      int ref_index = -1;
      REP(i, N){
        vector<Point> ps = crosspointLC(laser, CV[i]);
        REP(j, ps.size()){
          Point p = ps[j];
          if(dot(laser.vector(), p - laser[0]) < EPS) continue;
          if((ref_point - laser[0]).abs() > (p - laser[0]).abs()){
            ref_index = i;
            ref_point = p;
          }
        }
      }
      if(ref_index == -1) break;
      const Circle& C = CV[ref_index];
      Line mid_line(C, ref_point);
      laser = Line(ref_point, reflection(mid_line, laser[0]));
    }
    Point ans = laser[0];
    printf("%.8lf %.8lf %.8lf\n", ans.x, ans.y, ans.z);
  }
  return 0;
}

Measured memory_bytes: 1264