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 -(point p){
		return point(x-p.x,y-p.y);
	}
};
// ??????p3??¨p1p2????????§ 
double direction(point p1, point p2, point p3) {
	return (p2.x - p1.x)*(p3.y - p2.y) - (p3.x - p2.x)*(p2.y - p1.y);
}
bool isjiao(point p1,point p2,point p3,point p4){
	// ?????????????????????????????¨????????????????????????
	double a,b,c,d;
	a=direction(p1,p2,p3);
	b=direction(p1,p2,p4);
	c=direction(p3,p4,p1);
	d=direction(p3,p4,p2);
	if(abs(a+b)<max(abs(a),abs(b))&&abs(c+d)<max(abs(c),abs(d)))return true;
	return false; 
}
double waiji(point p1,point p2){
	return p1.x*p2.y-p1.y*p2.x;
}
double neiji(point p1,point p2){
	return p1.x*p2.x+p1.y*p2.y;
}
// ?????????????????????????§???????		
double dis(point p,point p1,point p2){
	point v1,v2,v;
	v1=p2-p1;
	v2=p1-p2;
	v=p-p1;
	if(neiji(v,v1)<0)
		return sqrt((p.x-p1.x)*(p.x-p1.x)+(p.y-p1.y)*(p.y-p1.y));
	v=p-p2;
	if(neiji(v,v2)<0)
		return sqrt((p.x-p2.x)*(p.x-p2.x)+(p.y-p2.y)*(p.y-p2.y));
	// ?????°??????????????´??????
	return abs(waiji(v,v2))/sqrt(v2.x*v2.x+v2.y*v2.y); 
}
point p1,p2,p3,p4;
double solve(){
// ??????????????????1???????????°????????????????????????2???????????°??????1??????		
	if(isjiao(p1,p2,p3,p4))return 0;
	double res=min(dis(p1,p3,p4),dis(p2,p3,p4));
	res=min(res,dis(p3,p1,p2));
	res=min(res,dis(p4,p1,p2));
	return res;
}
int main(){
//	freopen("a.txt","r",stdin);
	int T;
	cin>>T;
	while(T--){
		cin>>p1.x>>p1.y;
		cin>>p2.x>>p2.y;
		cin>>p3.x>>p3.y;
		cin>>p4.x>>p4.y;
		printf("%.10f\n",solve()); 
	}
	return 0;
}