403104: GYM101005 G Segments

Memory Limit:20 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Segmentstime limit per test1 secondmemory limit per test20 megabytesinputstandard inputoutputstandard output

You are given N segments in the xOy plane. Find the shortest closed broken line that contains all the given segments. A closed broken line is defined as a series of segments A[1] - A[2], A[2] - A[3] ... A[K - 1] - A[K], A[K] - A[1], where A is an array of points on the plane. The line can intersect itself.

Input

The first line contains T, the number of tests to follow. Then T tests follow. For each test, the first line contains an integer N(), followed by N lines, each describing a line segment by giving 4 real numbers, the x and y coordinates of the first end of the segment, and then the x and y coordinates of the second end of the segment.

Output

Your output file should contain T real numbers, representing the minimum length of the shortest closed broken line containing all the line segments. Your output should have a precision of 1.e - 6.

ExampleInput
2
2
1 1 1 2
1 1 2 2
3
-931.693980 781.297764 -767.512077 1305.542158
933.100984 -166.303237 1225.734021 -125.170151
320.771418 -163.911119 -148.087080 -332.428961
Output
1.000000
4427.669962

加入题单

算法标签: