Problem: For given two segments s1 and s2, print the distance between them.

s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3.

Constraints

* 1 ≤ q ≤ 1000
* -10000 ≤ xpi, ypi ≤ 10000
* p0 ≠ p1 and p2 ≠ p3.

Input

The entire input looks like:


q (the number of queries)
1st query
2nd query
...
qth query


Each query consists of integer coordinates of end points of s1 and s2 in the following format:


xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3


Output

For each query, print the distance. The output values should be in a decimal fraction with an error less than 0.00000001.

Example

Input

3
0 0 1 0 0 1 1 1
0 0 1 0 2 1 1 2
-1 0 1 0 0 1 0 -1


Output

1.0000000000
1.4142135624
0.0000000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>

using namespace std;
#define eps = (1e-10);
//点
struct Point{
    double x,y;
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    Point operator + (Point p){return Point(x+p.x,y+p.y);}
    Point operator - (Point p){return Point(x-p.x,y-p.y);}
    Point operator * (double a){return Point(a*x,a*y);}
    Point operator / (double a){return Point(x/a,y/a);}
    double norm(){return x*x+y*y;}//模的平方
    double ABS() {return sqrt(norm());}//模
};
//线段
struct Segment{
    Point p1,p2;
};
//点积
double dot(Point a,Point b){
    return a.x*b.x+a.y*b.y;
}
//叉积
double cross(Point a,Point b){
    return a.x*b.y-a.y*b.x;
}
bool Intersect(Segment A ,Segment B){
    if(max(B.p1.x,B.p2.x)<min(A.p1.x,A.p2.x)) return 0;
    if(max(B.p1.y,B.p2.y)<min(A.p1.y,A.p2.y)) return 0;
    if(max(A.p1.y,A.p2.y)<min(B.p1.y,B.p2.y)) return 0;
    if(max(A.p1.x,A.p2.x)<min(B.p1.x,B.p2.x)) return 0;
    if(cross(A.p1-B.p1,A.p2-B.p1)*cross(A.p1-B.p2,A.p2-B.p2)>0) return 0;
    if(cross(B.p1-A.p1,B.p2-A.p1)*cross(B.p1-A.p2,B.p2-A.p2)>0) return 0;
    return 1;
}
double Pointdis(Point a,Point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double Segdis(Point A ,Segment B){
    Point alp1=A-B.p1;
    Point beta1=B.p2-B.p1;
    Point alp2=A-B.p2;
    Point beta2=B.p1-B.p2;
    if(dot(alp1,beta1)<0||dot(alp2,beta2)<0){
        return min(Pointdis(A,B.p1),Pointdis(A,B.p2));
    }
    double a=B.p1.y-B.p2.y;
    double b=B.p2.x-B.p1.x;
    double c=B.p1.y*(B.p1.x-B.p2.x)-B.p1.x*(B.p1.y-B.p2.y);
    return fabs(a*A.x+b*A.y+c)/sqrt(a*a+b*b);
}
int main(){
    int q;
    scanf("%d",&q);
    while(q--){
        Segment A,B;
        scanf("%lf %lf %lf %lf",&A.p1.x,&A.p1.y,&A.p2.x,&A.p2.y);
        scanf("%lf %lf %lf %lf",&B.p1.x,&B.p1.y,&B.p2.x,&B.p2.y);
        if(Intersect(A,B)){
            cout<<0<<endl;continue;
        }
        double ans=min(Segdis(A.p1,B),min(min(Segdis(A.p2,B),Segdis(B.p1,A)),Segdis(B.p2,A)));
        printf("%.10lf\n",ans);
    }
    return 0;
}