GCJ1C09B - Center of Mass

You are studying a swarm of N fireflies. Each firefly is moving in a straight line at a constant speed. You are standing at the center of the universe, at position (0, 0, 0). Each firefly has the same mass, and you want to know how close the center of the swarm will get to your location (the origin).

You know the position and velocity of each firefly at t = 0, and are only interested in t ≥ 0. The fireflies have constant velocity, and may pass freely through all of space, including each other and you. Let M(t) be the location of the center of mass of the N fireflies at time t. Let d(t) be the distance between your position and M(t) at time t. Find the minimum value of d(t), dmin, and the earliest time when d(t) = dmin, tmin.

Input

The first line of input contains a single integer T, the number of test cases. Each test case starts with a line that contains an integer N, the number of fireflies, followed by N lines of the form

x y z vx vy vz

Each of these lines describes one firefly: (x, y, z) is its initial position at time t = 0, and (vx, vy, vz) is its velocity.

Output

For each test case, output

Case #X: dmin tmin

where X is the test case number, starting from 1. Any answer with absolute or relative error of at most 10-6 will be accepted.

Limits

All the numbers in the input will be integers.
1 ≤ T ≤ 100
The values of x, y, z, vx, vy and vz will be between -5000 and 5000, inclusive.

Large dataset

3 ≤ N ≤ 500

Sample

Input
3
3
3 0 -4 0 0 3
-3 -2 -1 3 0 0
-3 -1 2 0 3 0
3
-5 0 0 1 0 0
-7 0 0 1 0 0
-6 3 0 1 0 0
4
1 2 3 1 2 3
3 2 1 3 2 1
1 0 0 0 0 -1
0 10 0 0 -10 -1

Output
Case #1: 0.00000000 1.00000000
Case #2: 1.00000000 6.00000000
Case #3: 3.36340601 1.00000000

Notes

Given N points (xi, yi, zi), their center of the mass is the point (xc, yc, zc), where:

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

Added by:Shafaet
Date:2013-05-07
Time limit:1s-20s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Google Codejam 2009, Round 1C, Problem B

hide comments
2015-12-15 05:35:51 maurice37
Everyone getting the correct output but wrong answer, try using printf("%.8f")
2015-06-23 08:41:05 gamer496
final test is wrong last input line has only five inputs
2015-06-15 19:26:59 da jOkEr
my 70th... Can be Solved using 2 approaches.. my 70th :)
2014-10-08 14:13:23 Anmol Garg
100th! :D
2014-06-04 20:01:57 Vikas Yadav
easy one!!! My 50th :D
2014-01-15 10:05:51 Ashwini
good ques. silly mistake cost me 4 wa. AC finally
2013-08-09 17:56:58 piyush
finally ac :) :)
2013-06-20 12:54:40 :|
AC ! thanx Tjandra
2013-06-20 11:02:49 ABHISHEK004
aahh..!!! finally accepted after many WA...
2013-06-19 08:40:06 ABHISHEK004
getting WA but correct output
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.