SP9509 CYLINDES - Shortest Path on a Cylinder

Description

Ant Smart is on a surface of cylinder now. He wants to move to another position of the cylinder’s surface. Like many other animals named Smart, he wants to find out the shortest path from one point to another. Unfortunately, Ant Smart is not enough smart to solve this question now. It is your task to find out the answer.

Input Format

There are several test cases in this problem. The number of them is about 1000. The first line of input contains a single integer denoting the number of test cases. For each test case, the first line contains two integers - the radius and height of the cylinder, separated by spaces. For the next two lines, each line contains three integers: **h**, **a** and **r** (0

Output Format

For each test case, output only one line contains the length of the shortest path on the surface of cylinder. We accept solutions with absolute error less than 10 $ ^{-2} $ in at least 99% of the test cases.