Center of Mass of a Firefly Swarm

Each firefly moves linearly at constant velocity; find the minimum distance from the origin to the swarm's center of mass over t >= 0 and the earliest time it occurs, printed to eight exact decimals.

Medium6MathGeometryImplementationBrute forceNo attempts yetTime limit5sMemory limit512 MB

Problem

You are watching a swarm of NN fireflies. Each firefly moves along a straight line at a constant speed. You stand at the origin (0,0,0)(0, 0, 0) of space. All fireflies have the same mass, and you want to know how close the center of the swarm comes to you.

You know the position and the velocity of every firefly at time t=0t = 0, and only times t0t \ge 0 matter. Velocities never change, and a firefly passes freely through anything, including the other fireflies and you. Let M(t)M(t) be the center of mass of the NN fireflies at time tt, and let d(t)d(t) be the distance between the origin and M(t)M(t). Find the minimum value dmind_{\min} of d(t)d(t) over t0t \ge 0, and the earliest time tmint_{\min} with d(tmin)=dmind(t_{\min}) = d_{\min}.

Input

The first line contains the number of test cases TT. Each test case starts with a line holding the number of fireflies NN, followed by NN lines of this form.

x y z vx vy vz

Each line describes one firefly. (x,y,z)(x, y, z) is its position at time t=0t = 0 and (vx,vy,vz)(v_x, v_y, v_z) is its velocity.

Limits

  • Every number in the input is an integer.
  • 1T1001 \le T \le 100
  • 3N5003 \le N \le 500
  • 5000x,y,z,vx,vy,vz5000-5000 \le x, y, z, v_x, v_y, v_z \le 5000

Output

For each test case print one line of this form.

Case #X: dmin tmin

XX is the test case number, starting from 1. Print dmind_{\min} first, then a single space, then tmint_{\min}. Round both values to eight digits after the decimal point and print all eight digits, rounding an exact half up. The rounding has to be exact, and tmint_{\min} can be larger than 10610^6, so double precision floating point alone may not carry enough digits.

Note

The center of mass of NN points (xi,yi,zi)(x_i, y_i, z_i) is the point (xc,yc,zc)(x_c, y_c, z_c) below.

xc = (x1 + x2 + ... + xN) / N
yc = (y1 + y2 + ... + yN) / N
zc = (z1 + z2 + ... + zN) / N