Center of Mass of a Firefly Swarm

Average the fireflies' positions and velocities to get the swarm's center of mass, then find the closest approach to the origin for t >= 0.

Easy3MathGeometryImplementationBrute forceInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

You are watching a swarm of NN fireflies. Each firefly moves along a straight line at a constant velocity. You stand at the center of the universe, at position (0,0,0)(0, 0, 0). Every firefly has the same mass, and you want to know how close the center of the swarm gets to you.

You know the position and the velocity of every firefly at time t=0t = 0, and only times t0t \ge 0 matter. The velocities never change, and the fireflies pass freely through all of space, including through each other and through 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 your position and M(t)M(t). Find the minimum value dmind_{min} of d(t)d(t), and the earliest time tmint_{min} at which d(t)=dmind(t) = d_{min}.

Input

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

x y z vx vy vz

Each of those lines 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
  • 5000x,y,z,vx,vy,vz5000-5000 \le x, y, z, v_x, v_y, v_z \le 5000
  • 3N103 \le N \le 10

Output

For each test case, print one line of the form

Case #X: dmin tmin

XX is the test case number, starting from 1. Print dmind_{min} and tmint_{min} each rounded to exactly eight digits after the decimal point, padded with zeros when a digit is missing. Round an exact halfway value up. Separate the two values with a single space.

Hint

Given NN points (xi,yi,zi)(x_i, y_i, z_i), their center of mass is the point (xc,yc,zc)(x_c, y_c, z_c) where

xc=x1+x2++xNN,yc=y1+y2++yNN,zc=z1+z2++zNNx_c = \frac{x_1 + x_2 + \dots + x_N}{N}, \qquad y_c = \frac{y_1 + y_2 + \dots + y_N}{N}, \qquad z_c = \frac{z_1 + z_2 + \dots + z_N}{N}