Best Route in ChefLand

All submissions for this problem are available.
ChefLand is a strange place. In the middle of deepest ocean, Codesea, there are two small islands P and Q. Also there is one big circular country, known as C in the middle of the ocean. This country do not allow anyone inside their airspace ever. However, there is roadways in the perimeter of the (circular) country. Anyone is allowed in the road at any time. A lot of airports are available in that circular road. One can take a flight from any point from the road. Similarly you can land at any point in the road. A lot of airports !
Little Ira is currently in island P . She has to go to island Q. The traveling cost per unit distance in the air is C_{A}. Traveling cost per unit distance in the road is C_{R}. A plane can fly anywhere except in the restricted zone, i.e., inside the circular airspace.
Ira wants to go to city Q using minimum cost. She can either travel directly from P to Q using a single flight (of course without violating the restricted zone). Or, she can fly from P to the circular roadway, then may be travel some distance using roadways and then again take a flight from the road to Q. She just wants to minimize the total traveling cost. Help her.
Notes :
 The whole ocean can be modeled as 2D Cartesian plane. Where the center of the circular road and Origin coincide.
 Islands P and Q can be assigned x and y coordinates, say P_{x} and P_{y} etc.
 Let the radius of the circle be R.
 Distance here is defined as euclidean distance.
 Cost will be distance multiplied by corresponding rate (C_{R} or C_{A}).
Input
 The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
 The only line of each test case contains five integers  P_{x}, P_{y}, Q_{x}, Q_{y} and R, and two real numbers  C_{A} and C_{R}. All space separated in that order.
 The real numbers will contain exactly three digits after decimal. There will be no leading zeros. Example  zero will be represented as 0.000 and not 00.000 etc.
 P and Q lies strictly outside the circle C
Output
 For each test case, output a single line containing the minimum cost in which her tour can be completed.
 Your output will be considered correct if it is within the error of 0.01 with the jury's output.
Constraints
 1 ≤ T ≤ 100
 10^{4} ≤ P_{x}, P_{y}, Q_{x}, Q_{y} ≤ 10^{4}
 0 ≤ Ca, Cr ≤ 10^{3}
 1 ≤ R ≤ 10^{4}
Example
Input: 3 4 0 4 1 2 100.000 0.002 2 0 2 0 1 100.000 0.001 2 0 2 10 1 100.000 0.001 Output: 412.322149 200.003142 1000.000000
Explanation
Example case 1. See the image above for illustration.
Author:  triveni 
Tags  triveni 
Date Added:  30012016 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYP3 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 