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 EPS (1e-10)
#define equal(x,y)  (fabs(x-y)<EPS)
enum Status{
	COUNTER_CLOCKWISE=1,CLOCKWISE=-1,ONLINE_BACK=2,ONLINE_FRONT=-2,ON_SEGMENT=0
};
struct Point{
	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);
	}
};
typedef Point Vector;
struct Segment{
	Point p1,p2;
	Segment(){	}
	Segment(Point _p1,Point _p2):p1(_p1),p2(_p2){}
};
typedef Segment Line;
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;
}
double norm(const Vector & v){						//范数 
	return dot(v,v);
}
double abs(const Vector & v){						//模长 
	return sqrt(norm(v));
}
Point project(Segment s,Point p){					//点在直线上的投影坐标 
	Vector base=s.p2-s.p1,v=p-s.p1;
	double len = dot(base,v)*(1.0/norm(base));
	return s.p1+base*len;
}
Point reflect(Segment s,Point p){					//点关于直线的轴对称点 
	Point proj=project(s,p);
	return proj*2.0-p;
}
int ccw( Point p1, Point p2,  Point p3){			//判断三点的相对位置 
	Vector v1=p2-p1,v2=p3-p1;
	if(cross(v1,v2)<-EPS) return CLOCKWISE;
	if(cross(v1,v2)>EPS) return COUNTER_CLOCKWISE;
	if(dot(v1,v2)<-EPS) return ONLINE_BACK;
	if(norm(v1)<norm(v2)) return ONLINE_FRONT;
	return ON_SEGMENT;
}
bool intersect(Point p1,Point p2,Point p3,Point p4){//线段相交 
	return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
				ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}
bool intersect(Segment s1,Segment s2){
	return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}
double distanceLP(Line l,Point p){					//点到直线的距离 
	Vector v1=l.p2-l.p1,v2=p-l.p1;
	return fabs(cross(v1,v2))/abs(v1);
}
double distanceSP(Segment s,Point p){				//点到线段的距离
	if(dot(p-s.p2,s.p1-s.p2)>EPS&& dot(p-s.p1,s.p2-s.p1)>EPS) 
		return distanceLP(s,p);	
	double len1=abs(s.p1-p),len2=abs(s.p2-p);
	return min(len1,len2);
}
double distanceSS(Segment s1,Segment s2){			//两线段间距离
	if(intersect(s1,s2)) return 0.0;
	double len[]={distanceSP(s1,s2.p1),distanceSP(s1,s2.p2),
					distanceSP(s2,s1.p1),distanceSP(s2,s1.p2)};
	double minlen=len[0];
	for(int i=1;i<4;i++)
		if(minlen>len[i]) minlen=len[i];
	return minlen;
}
int main(){
	double x[4],y[4];
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>x[0]>>y[0]>>x[1]>>y[1];
		cin>>x[2]>>y[2]>>x[3]>>y[3];
		printf("%.10f\n", distanceSS(Segment(Point(x[0],y[0]),Point(x[1],y[1])),Segment(Point(x[2],y[2]),Point (x[3],y[3])) ) );
	}
	return 0;
}