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:
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define nep next_permutation
#define MOD 1000000007ll
#define MIN (1e-10)
#define equal(a,b) (abs((a)-(b))<MIN)
#define v2 ten
#define chokusen senbun
#define kakkei vec<ten>
using namespace std;
void solve();
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}
struct pea{
	ll f,s;
	bool operator<(const pea &p)const{
		return f!=p.f?f<p.f:s<p.s;
	};
};
struct tri{
	ll f,s,t;
	bool operator<(const tri &p)const{return f<p.f;};
};
class ten{
public:
	ld x,y;
	ten operator+(ten p){return{x+p.x,y+p.y};}
	ten operator-(ten p){return{x-p.x,y-p.y};}
	ten operator*(ld k){return{k*x,k*y};}
	ten operator/(ld k){return{x/k,y/k};}
	ld abs(){return sqrt(abs2());}
	ld abs2(){return x*x+y*y;};
	bool operator<(const ten &p)const{return x!=p.x?x<p.x:y<p.y;};
	bool operator==(const ten &p)const{return (-MIN<x-p.x)&&(x-p.x<MIN)&&(-MIN<y-p.y)&&(y-p.y<MIN);};
	ld naiseki(v2 b){return x*b.x+y*b.y;}
	ld gaiseki(v2 b){return x*b.y-y*b.x;}
};
struct senbun{ten p1,p2;};
struct en{ten o;ld r;};
ten shaei(ten p,chokusen l){
	v2 a=l.p2-l.p1;
	return l.p1+a*a.naiseki(p-l.p1)/a.abs2();
}
ten hansha(ten p,chokusen l){return shaei(p,l)*2-p;}
ld tenchoku(ten p,chokusen l){
	v2 a=l.p2-l.p1;
	return abs(a.gaiseki(p-l.p1))/a.abs();
}
ld tensen(ten p,senbun s){
	if((p-s.p1).naiseki(s.p2-s.p1)<0)return (p-s.p1).abs();
	if((p-s.p2).naiseki(s.p1-s.p2)<0)return (p-s.p2).abs();
	return tenchoku(p,s);
}
ll ccw(ten p0,ten p1,ten p2){
	v2 a=p1-p0,b=p2-p0;
	if(a.gaiseki(b)>MIN)return -1;//012反時計回り
	if(a.gaiseki(b)<-MIN)return 1;//012時計回り
	if(a.naiseki(b)<-MIN)return -2;//102
	if(a.abs2()<b.abs2())return 2;//012
	return 0;//021
}
bool majiwaru(senbun s,senbun t){return ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2)<=0&&ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2)<=0;}
ld sensen(senbun s,senbun t){
	if(majiwaru(s,t))return 0;
	return min({tensen(s.p1,t),tensen(s.p2,t),tensen(t.p1,s),tensen(t.p2,s)});
}
void solve(){
	ll n;cin>>n;
	cout<<sep(10);
	rep(i,0,n){
		senbun s1,s2;
		ld a,b,c,d;
		cin>>a>>b>>c>>d;
		s1={{a,b},{c,d}};
		cin>>a>>b>>c>>d;
		s2={{a,b},{c,d}};
		cout<<sensen(s1,s2)<<kai;
	}
}