This page is still under construction.

Parts of this page are still being built. What you see may change.

Interstellar Fantasy

Interview

Time limit1sMemory limit256 MB

Summary
Given a sphere obstacle and two points outside or on it, find the shortest path length from s to t that never enters the sphere.
Level

Medium6 of 10

Topics
Geometry, Math, Implementation, Shortest path
Solved
No attempts yet

Problem

Unfortunately, the boy finally went bankrupt. Watching his receding figure, Rikka understood more about the world, but she is still herself. She still sat on the tower and spent time in the low gravity, feeling lost.

She looked at the deep dark sky, where the blue round Earth was shining overhead. Rikka thought about her family, her friends, and her homeland. Is she in a dream or a "real" world? The girl of chunibyo felt afraid for the first time since the journey began.

She saw a bright star traveling fast around the earth, maybe a geostationary space station. How could she get there? Daydreaming started again.

In other words, Rikka wonders about the minimum distance she needs to travel from her position ss to the position of the star tt, while a sphere, the earth, stays there as an obstacle. They are in a 3-dimensional Euclidean space. ss and tt may be at the same position.

Input

The first line contains an integer T(1≤T≤1000)T (1 \leq T \leq 1000), the number of test cases. Then TT test cases follow.

Each test case contains two lines.

The first line contains four integers ox,oy,oz,ro_x, o_y, o_z, r, the position in each dimension of the center of the sphere oo and its radius.

The second line contains six integers sx,sy,sz,tx,ty,tzs_x, s_y, s_z, t_x, t_y, t_z, the position in each dimension of the starting point ss and the terminal point tt, respectively. Note that ss and tt may be at the same position.

It is guaranteed that neither ss nor tt is strictly inside the obstacle, and each value of a position or a radius in the input belongs to [1,1000][1, 1000].

Output

Output one number, the minimum distance from ss to tt without entering the sphere obstacle. Your answer is considered correct if the absolute or relative error doesn't exceed 10−610^{-6}.

Examples1

  1. Example 1

    Input
    2
    2 1 1 1
    1 1 1 3 1 1
    2 1 1 1
    1 2 2 3 1 1
    
    Expected output
    3.14159265
    2.64517298