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;
const double EPS = 1e-7;
const double INF = 1e12;
struct Vec {
    double x,y;
    Vec(){}
    Vec(double x,double y){ this->x=x,this->y=y; }
    void read(){ scanf("%lf%lf",&x,&y); }
    void prt() {printf("%.9f %.9f\n",x,y); }
    double len(){ return sqrt(x*x+y*y); }
    double len2(){ return x*x+y*y; }
    
    Vec operator+(const Vec&o)const{ return Vec(x+o.x,y+o.y); }
    Vec operator-(const Vec&o)const{ return Vec(x-o.x,y-o.y); }
    Vec operator*(const double&k)const{ return Vec(k*x,k*y); }
    double operator*(const Vec&o)const {return x*o.x+y*o.y; }
    double operator^(const Vec&o)const {return x*o.y-y*o.x; }
    Vec rotate(double ang){ return Vec(x*cos(ang)-y*sin(ang), x*sin(ang)+y*cos(ang)); }
    Vec change(double l){ if(len()<EPS) return *this; return (*this)*(l/len()); }
    double disToLine(Vec A, Vec B) {
        return abs((A-*this)^(B-*this))/(B-A).len();
    }
    Vec Reflection(Vec A,Vec B){
        Vec P = *this;
        double dis=P.disToLine(A,B);
        int sgn=(((B-A)^(P-A))>=0)?-1:+1;
        return (*this)+(B-A).rotate(acos(-1)/2).change(dis)*sgn;
    }
};

Vec Lineintersect(Vec A1,Vec A2,Vec B1,Vec B2) {
    if (abs((A2-A1)^(B2-B1)) < EPS) return Vec(INF,INF);
    return A1 + (A2 - A1) * ( (((A2-A1)^(B2-B1)) - ((A2-B1)^(B2-B1))) / ((A2-A1)^(B2-B1)) );
}

Vec Segintersect(Vec A1,Vec A2,Vec B1,Vec B2) {
    Vec P = Lineintersect(A1,A2,B1,B2);
    //P.prt();
    if ((P-A1)*(P-A2)<=0 && (P-B1)*(P-B2)<=0) return P; 
    return Vec(INF,INF);
}

bool onseg(Vec P,Vec A,Vec B){
    if(P.disToLine(A,B) > EPS) return 0;
    return (P-A)*(P-B) <= 0;
}
double minDis(Vec P,Vec A,Vec B){
    double ans=min((A-P).len(),(B-P).len());
    Vec H = P.Reflection(A,B);
    if(onseg(H,A,B)) ans=min(ans,(H-P).len());    
    return ans;
}

Vec A,B,C,D; int q;
int main(){
    scanf("%d",&q);
    while(q--){
        A.read(); B.read(); C.read(); D.read();
        if(Segintersect(A,B,C,D).x != INF) {
            printf("0\n"); continue;
        }
        double ans=min( min(minDis(A,C,D),minDis(B,C,D)),min(minDis(C,A,B),minDis(D,A,B)) );
        printf("%.8f\n", ans);
    }
}