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<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct Point{double x,y;};
Point operator -(Point a,Point b){return (Point){a.x-b.x,a.y-b.y};}
double cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
double dot(Point a,Point b){return a.x*b.x+a.y*b.y;}
double norm(Point a){return a.x*a.x+a.y*a.y;}
double abs(Point a){return sqrt(norm(a));}
void read(Point &a){a.x=read(),a.y=read();}
int Clockwise(Point p0,Point p1,Point p2)
{
	Point v1=p1-p0,v2=p2-p0;
	if(cross(v1,v2)>0)return -2;
	if(cross(v1,v2)<0)return 2;
	if(dot(v1,v2)<0)return -1;
	if(norm(v1)<norm(v2))return 1;
	return 0;
}
bool intersectSS(Point p0,Point p1,Point p2,Point p3)
{
	if(Clockwise(p0,p1,p2)*Clockwise(p0,p1,p3)>0)return 0;
	if(Clockwise(p2,p3,p0)*Clockwise(p2,p3,p1)>0)return 0;
	return 1;
}
double getdistanceLP(Point p0,Point p1,Point p2)
{
	double x=fabs(cross(p1-p0,p2-p0));
	return x/abs(p1-p0);
}
double getdistanceSP(Point p0,Point p1,Point p2)
{
	if(dot(p1-p0,p2-p0)<0)return abs(p2-p0);
	if(dot(p0-p1,p2-p1)<0)return abs(p2-p1);
	return getdistanceLP(p0,p1,p2);
}
double getdistanceSS(Point p0,Point p1,Point p2,Point p3)
{
	if(intersectSS(p0,p1,p2,p3))return 0;
	return min(min(getdistanceSP(p2,p3,p0),getdistanceSP(p2,p3,p1)),
			   min(getdistanceSP(p0,p1,p2),getdistanceSP(p0,p1,p3)));
}
int main()
{
	int q=read();while(q--)
	{
		Point p0,p1,p2,p3;
		read(p0),read(p1),read(p2),read(p3);
		printf("%.10lf\n",getdistanceSS(p0,p1,p2,p3));
	}
	return 0;
}