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 <cmath>
//#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#define EPS (1e-10)
using namespace std;
static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;
class Point{
public:
    double x,y;
    Point(double x=0, double y=0):x(x),y(y){}
    Point operator +(const Point &p){
        return Point(x+p.x,y+p.y);
    }
    Point operator -(const Point &p){
        return Point(x-p.x,y-p.y);
    }
    Point operator *(double k){
        return Point(k*x,k*y);
    }
    Point operator /(double k){
        return Point(x/k,y/k);
    }

    double norm(){
        return x*x+y*y;
    }
    double abs(){
        return sqrt(norm());
    }
};



class segment{
public:
    Point p1,p2;
};
typedef Point Vector;
double dot(const Vector &v1,const Vector &v2){
    return v1.x*v2.x+v1.y*v2.y;
}
double cross(const Vector &v1,const Vector &v2){
    return v1.x*v2.y-v1.y*v2.x;
}
bool isParallel(const Vector &v1,const Vector &v2){
    if(fabs(cross(v1,v2)-0.0)<EPS)return true;
    return false;
}
bool isOrthogonal(const Vector &v1,const Vector &v2){
    if(fabs(dot(v1,v2)-0.0)<EPS)return true;
    return false;
}
Point projection( Point &p, Point &p1, Point &p2){
    Vector a=p-p1;
    Vector b=p2-p1;
    double r=dot(a,b);
    double pro_abs=r/b.norm();
    Vector res=b*pro_abs;
    return Point(res.x+p1.x,res.y+p1.y);
}
Point reflection(Point &p, Point &p1, Point &p2){
    Point pro=projection(p,p1,p2);
    Vector v=pro-p;
    v=v*2;
    return Point(v.x+p.x,v.y+p.y);
}
int ccw(Point &p, Point &p1, Point &p2){
    Vector a=p-p1;
    Vector b=p2-p1;
    if(cross(a,b)>0)return COUNTER_CLOCKWISE;
    if(cross(a,b)<0)return CLOCKWISE;
    if(dot(a,b)<0)return ONLINE_BACK;
    if(a.norm()>b.norm())return ONLINE_FRONT;
    return ON_SEGMENT;
}
bool intersect(segment &s1,segment &s2){
    if(ccw(s1.p1,s2.p1,s2.p2)*ccw(s1.p2,s2.p1,s2.p2)<=0 && ccw(s2.p1,s1.p1,s1.p2)*ccw(s2.p2,s1.p1,s1.p2)<=0)
        return true;
    return false;
}
double getDistanceSP(Point &p,segment &s){
    if(dot(p-s.p1,s.p2-s.p1)<0)return (p-s.p1).abs();
    if(dot(p-s.p2,s.p1-s.p2)<0)return (p-s.p2).abs();
    return fabs(cross(p-s.p1,s.p2-s.p1)/(s.p2-s.p1).abs());
}
double Distance(segment &s1,segment &s2){
    if(intersect(s1,s2))return 0;
    double min1=min(getDistanceSP(s1.p1,s2),getDistanceSP(s1.p2,s2));
    double min2=min(getDistanceSP(s2.p1,s1),getDistanceSP(s2.p2,s1));
    return min(min1,min2);
}
int main()
{
    int q,p0x,p0y,p1x,p1y,p2x,p2y,p3x,p3y;
    segment s1;
    segment s2;
    cin>>q;
    while(q>0){
        cin>>p0x>>p0y>>p1x>>p1y>>p2x>>p2y>>p3x>>p3y;
        s1.p1=Point(p0x,p0y);
        s1.p2=Point(p1x,p1y);
        s2.p1=Point(p2x,p2y);
        s2.p2=Point(p3x,p3y);
        printf("%.8f\n",Distance(s1,s2));
        q--;
    }
    return 0;
}