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;

#define ld long double
#define eps 1e-9

bool cmp(ld A , ld B){return A + eps > B && A - eps < B;}

struct vec{
	ld x , y;
	vec(ld _x = 0 , ld _y = 0) : x(_x) , y(_y){}
	friend vec operator +(vec A , vec B){return vec(A.x + B.x , A.y + B.y);}
	friend vec operator -(vec A , vec B){return vec(A.x - B.x , A.y - B.y);}
	friend ld operator *(vec A , vec B){return A.x * B.x + A.y * B.y;}
	friend ld operator %(vec A , vec B){return A.x * B.y - A.y * B.x;}
	friend vec operator *(vec A , ld B){return vec(A.x * B , A.y * B);}
	ld len(){return sqrt(x * x + y * y);}
	ld len2(){return x * x + y * y;}
	ld angle(){return atan2(y , x);}
};

struct segment{
	vec st , ed , dir;
	segment(vec _a = vec() , vec _b = vec()) : st(_a) , ed(_b) , dir(_b - _a){}
	friend bool havesect(segment A , segment B){
		ld P = A.st.x , Q = A.ed.x , X = B.st.x , Y = B.ed.x;
		if(Q < P) swap(P , Q);
		if(Y < X) swap(X , Y);
		if(X - eps > Q || P - eps > Y) return 0;
		P = A.st.y , Q = A.ed.y , X = B.st.y , Y = B.ed.y;
		if(Q < P) swap(P , Q);
		if(Y < X) swap(X , Y);
		if(X - eps > Q || P - eps > Y) return 0;
		return
			((B.st - A.st) % A.dir) * (A.dir % (B.ed - A.st)) > -eps &&
			((B.st - A.ed) % A.dir) * (A.dir % (B.ed - A.ed)) > -eps &&
			((A.st - B.st) % B.dir) * (B.dir % (A.ed - B.st)) > -eps &&
			((A.st - B.ed) % B.dir) * (B.dir % (A.ed - B.ed)) > -eps;
	}
	friend vec getsect(segment A , segment B){
		ld t = ((A.st - B.st) % B.dir) / (B.dir % A.dir);
		return A.st + (A.dir * t);
	}
	ld len(){return dir.len();}
	ld len2(){return dir.len2();}
};

ld dist(vec P , segment seg){//minimum dist from a point to a segment
	ld T = ((P - seg.st) * seg.dir) / seg.len2();
	if(T < 0) return (seg.st - P).len();
	else if(T > 1) return (seg.ed - P).len();
	else return (seg.st + (seg.dir * T) - P).len();
}

vec getvec(){ld x , y; cin >> x >> y; return vec(x , y);}
segment getseg(){vec A = getvec() , B = getvec(); return segment(A , B);}

int main(){
	int Q;
	for(cin >> Q ; Q ; --Q){
		segment P = getseg() , Q = getseg();
		if(havesect(P , Q)) cout << 0 << endl;
		else
			cout << fixed << setprecision(10) << min(min(dist(P.st , Q) , dist(P.ed , Q)) , min(dist(Q.st , P) , dist(Q.ed , P))) << endl;
	}
	return 0;
}