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>
#define db double
using namespace std;
int n;
db xp1,xp2,xp3,xp4,yp1,yp2,yp3,yp4;
db sum1,sum2,xa,xb,xc,xd,ya,yb,yc,yd;
db len(db xp1,db yp1,db xp2,db yp2,db xp3,db yp3){
	db l1=xp2-xp1,r1=yp2-yp1,l2=xp3-xp1,r2=yp3-yp1;
	if(l1*l2+r1*r2>=0&&abs((l1*l2+r1*r2)/sqrt(l1*l1+r1*r1))<=sqrt(l1*l1+r1*r1))return(abs((l1*r2-l2*r1)/sqrt(l1*l1+r1*r1)));
	else{
		db sum1=sqrt(l2*l2+r2*r2);
		db sum2=sqrt((xp3-xp2)*(xp3-xp2)+(yp3-yp2)*(yp3-yp2));
		return(min(sum1,sum2));
	}
} 
void solve(int t){
	db mn=40000;
	mn=min(mn,len(xp1,yp1,xp2,yp2,xp3,yp3));
	mn=min(mn,len(xp1,yp1,xp2,yp2,xp4,yp4));
	mn=min(mn,len(xp3,yp3,xp4,yp4,xp1,yp1));
	mn=min(mn,len(xp3,yp3,xp4,yp4,xp2,yp2));
	printf("%.10lf\n",mn);
}
int main(){	
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		scanf("%lf%lf%lf%lf",&xp1,&yp1,&xp2,&yp2);
		scanf("%lf%lf%lf%lf",&xp3,&yp3,&xp4,&yp4);
		xa=min(xp1,xp2);
		xb=max(xp1,xp2);
		ya=min(yp1,yp2);
		yb=max(yp1,yp2);
		xc=min(xp3,xp4);
		xd=max(xp3,xp4);
		yc=min(yp3,yp4);
		yd=max(yp3,yp4);
		if(xc>xb||xa>xd||yc>yb||ya>yd){
			solve(i);
			continue;
		}
		xb=xp4-xp3;
		yb=yp4-yp3;
		xa=xp1-xp3;
		ya=yp1-yp3;
		sum1=xa*yb-xb*ya;
		xa=xp2-xp3;
		ya=yp2-yp3;
		sum2=xa*yb-xb*ya;
		if(sum1*sum2>0){
			solve(i);
			continue;
		}
		xb=xp2-xp1;
		yb=yp2-yp1;
		xa=xp3-xp1;
		ya=yp3-yp1;
		sum1=xa*yb-xb*ya;
		xa=xp4-xp1;
		ya=yp4-yp1;
		sum2=xa*yb-xb*ya;
		if(sum1*sum2>0){
			solve(i);
			continue;
		}
		printf("0.0000000000\n");
	}
}