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 <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define db double
#define zero(x) (fabs(x)<eps)
#define sgn(x) (zero(x)?0:((x)>0?1:-1))
const db eps=1e-10;
struct point{
    db x,y;
    point(){}
    point(db x,db y):x(x),y(y){}
    point operator + (point B){ return point(x+B.x,y+B.y); }
    point operator - (point B){ return point(x-B.x,y-B.y); }
    point operator * (db k){ return point(k*x,k*y); }
    db operator * (point B){ return x*B.y-y*B.x; }
    db operator ^ (point B){ return x*B.x+y*B.y; }
    bool operator < (point B){ return (y>0)!=(B.y>0)?y>0:((*this)*B)>0; }
};
db dis2(point A,point B){ return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y); }
struct line{
    point A,B;
    line(){}
    line(point A,point B):A(A),B(B){}
};
point projection(line l,point P){
    point dir=l.B-l.A; P=P-l.A;
    return dir*((P^dir)/dis2(l.A,l.B))+l.A;
}
point reflection(line l,point P){
    return projection(l,P)*2-P;
}
int direction(point P0,point P1,point P2){
    db det=(P2-P0)*(P1-P0); return sgn(det);
}
bool parallel(line l1,line l2){
    return zero((l1.B-l1.A)*(l2.B-l2.A));
}
bool orthogonal(line l1,line l2){
    return zero((l1.B-l1.A)^(l2.B-l2.A));
}
bool intersect(line l1,line l2){
    int d1=direction(l1.A,l1.B,l2.A),d2=direction(l1.A,l1.B,l2.B);
    int d3=direction(l2.A,l2.B,l1.A),d4=direction(l2.A,l2.B,l1.B);
    if (d1*d2>0||d3*d4>0) return false;
    if (l1.A.x>l1.B.x) swap(l1.A.x,l1.B.x);
    if (l1.A.y>l1.B.y) swap(l1.A.y,l1.B.y);
    if (l2.A.x>l2.B.x) swap(l2.A.x,l2.B.x);
    if (l2.A.y>l2.B.y) swap(l2.A.y,l2.B.y);
    return !(l1.B.x<l2.A.x||l2.B.x<l1.A.x||l1.B.y<l2.A.y||l2.B.y<l1.A.y);
}
point cross_point(line l1,line l2){
    db s1=fabs((l2.B-l2.A)*(l1.A-l2.A)),s2=fabs((l2.B-l2.A)*(l1.B-l2.A));
    return l1.A+(l1.B-l1.A)*(s1/(s1+s2));
}
double dis(line l,point P){
    point proj=projection(l,P);
    if (min(l.A.x,l.B.x)-eps<proj.x&&proj.x<max(l.A.x,l.B.x)+eps)
        if (min(l.A.y,l.B.y)-eps<proj.y&&proj.y<max(l.A.y,l.B.y)+eps)
            return sqrt(dis2(P,proj));
    return sqrt(min(dis2(P,l.A),dis2(P,l.B)));
}
double distance(line l1,line l2){
    if (intersect(l1,l2)) return 0;
    return min(min(dis(l1,l2.A),dis(l1,l2.B)),min(dis(l2,l1.A),dis(l2,l1.B)));
}
int main(){
    int q; scanf("%d",&q);
    while (q--){
        db x1,y1,x2,y2; line l1,l2;
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); l1=line(point(x1,y1),point(x2,y2));
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); l2=line(point(x1,y1),point(x2,y2));
        printf("%.9f\n",distance(l1,l2));
    }
}