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;
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);
	}
	double operator ^(const point &b) const{
		return x*b.x+y*b.y;
	}
	double operator *(const point &b) const{
		return x*b.y-y*b.x;
	}
	point operator *(const double &b) const{
		return point(x*b,y*b);
	}
};
double len(point p){
	return p.x*p.x+p.y*p.y;
}
struct matrix{
	double xmin,xmax,ymin,ymax;
}a[2];
bool check(point p0,point p1,point p2,point p3){
	a[0].xmax=max(p0.x,p1.x);
	a[0].xmin=min(p0.x,p1.x);
	a[0].ymax=max(p0.y,p1.y);
	a[0].ymin=min(p0.y,p1.y);
	a[1].xmax=max(p2.x,p3.x);
	a[1].xmin=min(p2.x,p3.x);
	a[1].ymax=max(p2.y,p3.y);
	a[1].ymin=min(p2.y,p3.y);
	if(!(a[0].xmax<a[1].xmin || a[1].xmax<a[0].xmin || a[0].ymax<a[1].ymin || a[1].ymax<a[0].ymin)){
		if(((p1-p0)*(p2-p0))*((p1-p0)*(p3-p0))<=0 &&
		   ((p3-p2)*(p1-p2))*((p3-p2)*(p0-p2))<=0) return 1;
		else return 0;
	}
	else return 0;
}
double dist(point p,point p0,point p1){
	point q=(p1-p0)*(((p1-p0)^(p-p0))/len(p1-p0))+p0;
	if(min(p0.x,p1.x)<=q.x&&q.x<=max(p0.x,p1.x)&&min(p0.y,p1.y)<=q.y&&q.y<=max(p0.y,p1.y)) return sqrt(len(p-q));
	return min(sqrt(len(p0-p)),sqrt(len(p1-p)));
}
int main(){
	int n;
	point p0,p1,p2,p3;
	cin>>n;
	while(n--){
		cin>>p0.x>>p0.y>>p1.x>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y;
		if(check(p0,p1,p2,p3)) printf("%.10lf\n",0);
		else printf("%.10lf\n",min(min(dist(p0,p2,p3),dist(p1,p2,p3)),min(dist(p2,p0,p1),dist(p3,p0,p1))));
	}
	return 0;
}