#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    real EPS = 1e-8;

    struct Point {
        real x, y, z;
        Point() {}
        Point(real x, real y, real z) : x(x), y(y), z(z) {}
    };
    Point operator+(const Point& a, const Point& b) { return Point(a.x + b.x, a.y + b.y, a.z + b.z); }
    Point operator-(const Point& a, const Point& b) { return Point(a.x - b.x, a.y - b.y, a.z - b.z); }
    Point operator*(const Point& a, real k) { return Point(a.x * k, a.y * k, a.z * k); }
    Point operator/(const Point& a, real k) { return a * (1.0 / k); }
    istream& operator>>(istream& is, Point& p) { return is >> p.x >> p.y >> p.z; }
    ostream& operator<<(ostream& os, const Point& p) { return os << "Point(" << p.x << "," << p.y << "," << p.z << ")"; }
    real dot(const Point& a, const Point& b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
    real norm(const Point& a) { return sqrt(dot(a, a)); }
    real cos(const Point& a, const Point& b) { return dot(a, b) / (norm(a) * norm(b)); }
    real dist(const Point& a, const Point& b) {
        real dx = a.x - b.x;
        real dy = a.y - b.y;
        real dz = a.z - b.z;
        return sqrt(dx * dx + dy * dy + dz * dz);
    }

    struct Line {
        Point a, b;
        Line(Point a, Point b) : a(a), b(b) {}
    };
    Point projection(const Line& l, const Point& p) {
        Point u = (p - l.a), v = (l.b - l.a);
        return l.a + (v / norm(v)) * (dot(u, v) / norm(v));
    }
    Point reflection(const Line& l, const Point& p) {
        Point h = projection(l, p);
        return p + (h - p) * 2;
    }
    real dist(const Line& l, const Point& p) {
        Point q = projection(l, p);
        return norm(p - q);
    }

    int N;
    Point U;
    vector<Point> Q; vector<real> R;
    bool input() {
        cin >> N;
        if (N == 0) return false;
        cin >> U;
        Q.clear(); Q.resize(N);
        R.clear(); R.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> Q[i] >> R[i];
        }
        return true;
    }

    bool reflect(const Point& org, const Point& v, int sphere_index) {
        int n = sphere_index;
        Point p = Q[n] - org;
        real cos_phi = cos(v, p);
        if (cos_phi < -EPS) return false;
        return dist(Line(org, org + v), Q[n]) < R[n];
    }
    pair<Point, Point> ref(const Point& org, const Point& v, int sphere_index) {
        int n = sphere_index;
        Point p = Q[n] - org;
        real cos_phi = cos(v, p);
        real d = dist(org, Q[n]);
        real r = R[n];
        real x = d * cos_phi - sqrt( (d * cos_phi) * (d * cos_phi) - d * d + r * r );
        Point refpoint = org + v / norm(v) * x;
        Point refvector = reflection(Line(Q[n], refpoint), org) - refpoint;
        return make_pair(refpoint, refvector);
    }

    pair<Point, Point> next(const Point& org, const Point& v) {
        vector< pair<Point, Point> > refs;
        for (int i = 0; i < N; i++) {
            if (reflect(org, v, i)) {
                refs.push_back(ref(org, v, i));
            }
        }
        if (refs.empty()) throw "foo";
        pair<Point, Point> r = refs[0];
        real d = dist(org, refs[0].first);
        for (int i = 0; i < refs.size(); i++) {
            real nd = dist(org, refs[i].first);
            if (nd < d) {
                d = nd;
                r = refs[i];
            }
        }
        return r;
    }

    void solve() {
        Point org(0, 0, 0);
        Point u = U;
        try {
            while (true) {
                pair<Point, Point> r = next(org, u);
                org = r.first;
                u = r.second;
            }
        } catch (const char* e) {
            printf("%.8f %.8f %.8f\n", org.x, org.y, org.z);
        }
    }
}

int main() {
    while (input()) solve();
    return 0;
}

Measured memory_bytes: 1336