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 mkp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
typedef long long ll;

const ll MOD=1e9+7;
const double EPS=1e-9;
const double PI=acos(-1.0);
//const long double PI=acos(-1.0L);

struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}

    Point operator +(const Point &b) const {return Point(x+b.x,y+b.y);}
    Point operator -(const Point &b) const {return Point(x-b.x,y-b.y);}
    Point operator *(const double b) const {return Point(x*b,y*b);}
    Point operator /(const double b) const {return Point(x/b,y/b);}
};

struct Line{
    Point a,b;
    Line(){}
    Line(Point a,Point b):a(a),b(b){}
};

int sgn(double a) {return (a>EPS)-(a<-EPS);}
int sgn(double a,double b) {return sgn(a-b);}

double dot(const Point &a,const Point &b) {return (a.x*b.x+a.y*b.y);}
double cross(const Point &a,const Point &b) {return (a.x*b.y-a.y*b.x);}
double norm(const Point &p) {return dot(p,p);}
double abs(const Point &p) {return sqrt(norm(p));}

Point projection(const Point &p,const Line &l){
    double r=dot(p-l.a,l.b-l.a)/norm(l.b-l.a);
    return l.a+(l.b-l.a)*r;
}
Point reflection(const Point &p,const Line &l){
    return p+(projection(p,l)-p)*2;
}

//1:Counter_Clockwise -1:Clockwise
//2:a-b-c -2:c-a-b 0:a-c-b
int ccw(const Point &p,const Point &q){
    int s=sgn(cross(p,q));
    if(s!=0) return s;
    if(dot(p,q)<0) return -2;
    if(norm(p)<norm(q)) return 2;
    return 0;
}
int ccw(const Point &a,const Point &b,const Point &c){return ccw(b-a,c-a);}

bool isParallel(const Line &l,const Line &r){
    if(sgn(cross(l.b-l.a,r.b-r.a))==0) return true;
    return false;
}
bool isOrthogonal(const Line &l,const Line &r){
    if(sgn(dot(l.b-l.a,r.b-r.a))==0) return true;
    return false;
}

Point crosspoint(const Line &s,const Line &t){
    Point v=t.b-t.a;
    double d1=abs(cross(v,s.a-t.a));
    double d2=abs(cross(v,s.b-t.a));
    double w=d1/(d1+d2);
    return s.a+(s.b-s.a)*w;
}

double isIntersectedPL(const Point &p,const Line &l){
    return (sgn(abs(p-projection(p,l)))==0);
}
double isIntersectedPS(const Point &p,const Line &s){
    return (ccw(s.a,s.b,p)==0);
}
bool isIntersectedSS(const Line &s,const Line &t){
    if(ccw(s.b-s.a,t.a-s.a)*ccw(s.b-s.a,t.b-s.a)>0) return false;
    if(ccw(t.b-t.a,s.a-t.a)*ccw(t.b-t.a,s.b-t.a)>0) return false;
    return true;
}
double distancePL(const Point &p,const Line &l){
    return abs(p-projection(p,l));
}
double distancePS(const Point &p,const Line &s){
    Point h=projection(p,s);
    if(isIntersectedPS(h,s)) return abs(h-p);
    return min(abs(p-s.a),abs(p-s.b));
}
double distanceSS(const Line &s,const Line &t){
    if(isIntersectedSS(s,t)) return 0.0;
    return min(min(distancePS(s.a,t),distancePS(s.b,t)),min(distancePS(t.a,s),distancePS(t.b,s)));
}

int main(){
    int Q;
    cin>>Q;

    for(int q=0;q<Q;q++){
        Point P1,P2;
        cin>>P1.x>>P1.y>>P2.x>>P2.y;
        Point P3,P4;
        cin>>P3.x>>P3.y>>P4.x>>P4.y;

        Line L1(P1,P2);
        Line L2(P3,P4);
        double ans=distanceSS(L1,L2);
        cout<<fixed<<setprecision(10)<<ans<<endl;
    }

    return 0;
}