“Miyane!” This day Hana asks Miyako for help again. Hana plays the part of angel on the stage show of the cultural festival, and she is going to look for her human friend, Hinata. So she must find the shortest path to Hinata’s house.

The area where angels live is a circle, and Hana lives at the bottom of this circle. That means if the coordinates of circle’s center is (rx, ry)(rx,ry)and its radius is rr, Hana will live at (rx, ry - r)(rx,ry−r).

Apparently, there are many difficulties in this journey. The area which is located both outside the circle and below the line y = ryy=ry is the sea, so Hana cannot pass this area. And the area inside the circle is the holy land of angels, Hana cannot pass this area neither.

However, Miyako cannot calculate the length of the shortest path either. For the loveliest Hana in the world, please help her solve this problem!

Input

Each test file contains several test cases. In each test file:

The first line contains a single integer T(1 \le T \le 500)T(1≤T≤500) which is the number of test cases.

Each test case contains only one line with five integers: the coordinates of center rxrx 、 ryry, the radius rr, thecoordinates of Hinata’s house xx 、yy. The test data guarantees that y > ryy>ryand (x, y)(x,y) is out of the circle. (-10^2 \le rx,ry,x,y \le 10^2,0 < r \le 10^2)(−102≤rx,ry,x,y≤102,0<r≤102).

Output

For each test case, you should print one line with your answer (please keep 44 decimal places).

样例输入复制

2
1 1 1 2 2 
1 1 1 1 3

样例输出复制

2.5708
3.8264

对于本题我们显然可以先猜出一个结论就那就是若初始点与右边的点能连成直线那么自然走直线

else 那么就先走到切线处

如果用正弦定理推角度的话并不是十分的好算

但是如果我们采用极坐标的思想那么本题的代码就并不多了

#include<bits/stdc++.h>
using namespace std;

double pi=acos(-1);

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        double rx,ry,x,y,r;
        double ans;
        cin>>rx>>ry>>r>>x>>y;
        x-=rx;
        y-=ry;
        if(x<0) x=-x;
        if(x>=r)
        {
            ans=sqrt((x-r)*(x-r)+y*y)+pi*r/2.0;
            printf("%.4lf\n",ans);
        }
        else
        {
            double ang1,ang2,ang;
            ang2=atan(y/x)-acos(r/sqrt(x*x+y*y));
            ans=sqrt((x-(r*cos(ang2)))*(x-(r*cos(ang2)))+(y-(r*sin(ang2)))*(y-(r*sin(ang2))))+(ang2+pi/2.0)*r;
            printf("%.4lf\n",ans);
        }
    }
}