Spherical Mirrors

Time limit1sMemory limit128 MB

Problem

There are $N$ spherical mirrors in three-dimensional space.

A laser is fired from $(0,0,0)$ in the direction $(u,v,w)$. The laser always travels in a straight line.

Suppose a laser fired from a point $I$ is reflected at a point $Q$ on a spherical mirror. Let $N$ be a point that lies outside the mirror and on the straight line joining the mirror's center and $Q$. Then the laser is reflected in a direction $R$ that satisfies the following condition:

(1) $R$ lies in the plane determined by $I$, $Q$, and $N$, and $\angle IQN = \angle NQR$.

Write a program that finds the position of the point at which the laser is reflected for the last time.

Input

The first line contains the number of test cases $T$. For each test case, the first line contains the number of spherical mirrors $N$. The second line contains the direction $u$, $v$, $w$ in which the laser is fired, separated by spaces.

Each of the next $N$ lines contains four integers $x_i$, $y_i$, $z_i$, $r_i$ describing a spherical mirror whose center is $(x_i, y_i, z_i)$ and whose radius is $r_i$.

$1 \le N \le 100$

$-100 \le u, v, w \le 100$

$-100 \le x_i, y_i, z_i \le 100$

$5 \le r_i \le 30$

$u^2 + v^2 + w^2 > 0$

The distance between any two spherical mirrors is at least $0.1$. The point $(0,0,0)$ lies outside every spherical mirror and is at least $0.1$ away from each of them.

The laser is reflected by the spherical mirrors at least once and at most five times. Moreover, the angle of reflection $\theta$ (that is, $\angle NQR$, which equals $\angle IQN$) is always smaller than $85^\circ$.

Output

For each test case, output the coordinates of the last reflection point, separated by spaces. Every coordinate is rounded at the fourth decimal place and printed to three decimal places.