/*
分析:
计算几何,水。
2013-06-25
*/
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
using namespace std;
int main()
{
int T;
double k,k2,b,b2;
double x1,y1,x2,y2,x,y,xx,yy;
double tx,ty,dirx,diry;
double X1,Y1,X2,Y2,j1,j2;
cin>>T;
while(T--)
{
cin>>k;
scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x,&y);
b=y-k*x;
//向量判断异侧
xx=x+1;
yy=k*xx+b;
X1=x-xx;Y1=y-yy;
X2=x1-x;Y2=y1-y;
j1=X1*Y2-X2*Y1;
X2=x2-x;Y2=y2-y;
j2=X1*Y2-X2*Y1;
//如果同侧,找对称点
if(j1*j2>0)
{
if(k==0)
{
if(y2>y) y2=y-(y2-y);
else y2=y+(y-y2);
}
else
{
k2=-1/k;
b2=y2-k2*x2;
tx=(b-b2)/(k2-k);
ty=k2*tx+b2;
dirx=x2-tx;
diry=y2-ty;
x2=tx-dirx;
y2=ty-diry;
}
}
printf("%.2lf\n",sqrt(pow(x1-x2,2)+pow(y1-y2,2)));
}
return 0;
}