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<algorithm>
#include<stdio.h>
#include<cmath>
using namespace std;

struct point{
    int x,y;
};

struct line{
    point s,t;
};

struct bec{
    int x,y;
};

double keisan(point p, line l){
    bec p1,p2,bl,bm;
    p1.x = p.x-l.s.x; p1.y=p.y-l.s.y;
    p2.x = p.x-l.t.x; p2.y=p.y-l.t.y;

    bl.x = l.t.x-l.s.x; bl.y = l.t.y-l.s.y;
    bm.x=-1*bl.x; bm.y=-1*bl.y;

    double cp1,cp2;
    if(sqrt((double)p1.x*(double)p1.x+(double)p1.y*(double)p1.y)==0||sqrt((double)p2.x*(double)p2.x+(double)p2.y*(double)p2.y)==0) return 0;
    cp1 = ((double)p1.x*(double)bl.x+(double)p1.y*(double)bl.y)
    /(sqrt((double)p1.x*(double)p1.x+(double)p1.y*(double)p1.y)*sqrt((double)bl.x*(double)bl.x+(double)bl.y*(double)bl.y));
    cp2 = ((double)p2.x*(double)bm.x+(double)p2.y*(double)bm.y)
    /(sqrt((double)p2.x*(double)p2.x+(double)p2.y*(double)p2.y)*sqrt((double)bm.x*(double)bm.x+(double)bm.y*(double)bm.y));

    if(cp1<=0){
        return sqrt((double)p1.x*(double)p1.x+(double)p1.y*(double)p1.y);
    }
    else if(cp2<=0){
        return sqrt((double)p2.x*(double)p2.x+(double)p2.y*(double)p2.y);
    }
    else{
        double d = sqrt((double)p1.x*(double)p1.x+(double)p1.y*(double)p1.y);
        double k=d*cp1;
        double kyori = sqrt((double)bl.x*(double)bl.x+(double)bl.y*(double)bl.y);
        if(kyori==0) return d;
        double s=((double)l.t.y-(double)l.s.y)/kyori;
        double c=((double)l.t.x-(double)l.s.x)/kyori;
        return sqrt(((k*s+l.s.y)-p.y)*((k*s+l.s.y)-p.y)+((k*c+l.s.x)-p.x)*((k*c+l.s.x)-p.x));

    }
}

void solve(line l,line m){
    double a,b;
    long ta,tb,tc,td;
    ta=(m.s.x-m.t.x)*(l.s.y-m.s.y)+(m.s.y-m.t.y)*(m.s.x-l.s.x);
    tb=(m.s.x-m.t.x)*(l.t.y-m.s.y)+(m.s.y-m.t.y)*(m.s.x-l.t.x);
    tc=(l.s.x-l.t.x)*(m.s.y-l.s.y)+(l.s.y-l.t.y)*(l.s.x-m.s.x);
    td=(l.s.x-l.t.x)*(m.t.y-l.s.y)+(l.s.y-l.t.y)*(l.s.x-m.t.x);
    if(tc*td<0 && ta*tb<0){
        cout<<"0"<<endl;
    }
    else{
        a=min(keisan(l.s,m),keisan(l.t,m));
        b=min(keisan(m.s,l),keisan(m.t,l));
        printf("%.8f\n",min(a,b));
    }
}


int main(){
    int n,x0,x1,x2,x3,y0,y1,y2,y3;
    cin>>n;

    point s1,s2,t1,t2;
    line l,m;

    for(int i=0;i<n;i++){
        cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
        s1.x=x0; s1.y=y0;
        t1.x=x1; t1.y=y1;
        s2.x=x2; s2.y=y2;
        t2.x=x3; t2.y=y3;

        l.s=s1; l.t=t1;
        m.s=s2; m.t=t2;
        solve(l,m);
    }
    return 0;
}