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 For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef double db;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

namespace Geometry{
	const db eps = 1e-9;
	struct point{
		db x,y;
		inline point operator + (const point &p){return (point){x+p.x,y+p.y};}
		inline point operator - (const point &p){return (point){x-p.x,y-p.y};}
		inline db operator * (const point &p){return x*p.x+y*p.y;}
		inline point operator / (const db &v){return (point){x/v,y/v};}
		inline point operator * (const db &v){return (point){x*v,y*v};}
	};
	typedef point vec;
	inline db dot(vec a,vec b){return a.x*b.x+a.y*b.y;}
	inline db sqr(db x){return x*x;}
	inline db dis(point a,point b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
	inline db dis2(point a,point b){return sqr(a.x-b.x)+sqr(a.y-b.y);}
	inline db cross(vec a,vec b){return a.x*b.y-a.y*b.x;}
	struct line{
		point a,b;
	};
	inline point projection(point A,line b){
		point B=b.a,C=b.b;
		vec BA=A-B,BC=C-B,BD=BC*(BA*BC/dis2(B,C));
		return B+BD;
	}
	inline point reflection(point A,line b){
		point D=projection(A,b);
		return (point){D.x*2-A.x,D.y*2-A.y};
	}
	inline int Counter_Clockwise(point A,line b){
		point B=b.a,C=b.b;
		db f1=cross(C-B,A-B);
		if (fabs(f1)>eps) return (f1<0?2:1);
		db f2=(C-B)*(A-B);
		if (f2<0) return 3;
		return dis(B,C)<dis(A,B)?4:5;
	}
	inline int checkline(line a,line b){
		vec A=a.b-a.a,B=b.b-b.a;
		db f1=A*B;
		if (fabs(f1)<=eps) return 1;
		return dis(a.a,a.b)*dis(b.a,b.b)-fabs(f1)<=eps?2:0;
	}
	inline int checkseg(line a,line b){
		point A=a.a,B=a.b,C=b.a,D=b.b;
		if (max(A.x,B.x)<min(C.x,D.x)) return 0;
		if (min(A.x,B.x)>max(C.x,D.x)) return 0;
		if (max(A.y,B.y)<min(C.y,D.y)) return 0;
		if (min(A.y,B.y)>max(C.y,D.y)) return 0;
		db s=cross(B-A,C-A),h=cross(B-A,D-A);
		if (s*h>=eps) return 0;
		db i=cross(D-C,A-C),t=cross(D-C,B-C);
		return i*t<=eps;
	}
	inline point crosspoint(line a,line b){
		point A=a.a,B=a.b,C=b.a,D=b.b;
		db s1=fabs(cross(B-A,C-A)),s2=fabs(cross(B-A,D-A));
		vec CO=(D-C)*(s1/(s1+s2));
		return C+CO;
	}
	inline db dis(point	A,line b){
		point B=b.a,C=b.b,D=projection(A,b);
		int tmp=Counter_Clockwise(D,b);
		if (tmp==3) return dis(B,A);
		if (tmp==4) return dis(C,A);
		if (tmp==5) return dis(D,A);
	}
	inline db dis(line a,line b){
		if (checkseg(a,b)) return 0;
		db s=dis(a.a,b),h=dis(a.b,b),i=dis(b.a,a),t=dis(b.b,a);
		return min({s,h,i,t});
	}
};
using namespace Geometry;

int main(){
//	freopen("data.in","r",stdin);
	int T;scanf("%d",&T);
	while (T--){
		line a;scanf("%lf%lf%lf%lf",&a.a.x,&a.a.y,&a.b.x,&a.b.y);
		line b;scanf("%lf%lf%lf%lf",&b.a.x,&b.a.y,&b.b.x,&b.b.y);
		printf("%0.10lf\n",dis(a,b));
	}
}